This guide provides step-by-step instructions for setting up Python, pip, virtual environments, and Django on a Linux system.
Ensure Python 3 is installed on your system. You can check this by running:
python3 --versionpip3 is the package manager for Python, allowing you to easily install and manage Python libraries.
sudo apt update
sudo apt install python3-pip
pip3 --version # Verify the installationThe python3-venv module is used to create isolated Python environments.
sudo apt update
sudo apt install python3-venv- Create the virtual environment:
python3 -m venv myenv && source myenv/bin/activatepip3 install django && django-admin startproject myproject . && python manage.py startapp myapp && python manage.py migrate && python manage.py createsuperuser --username ad --email admin@example.com && pip3 freeze > requirements.txt && python manage.py runserverOnce inside the virtual environment, install Django:
pip3 install django djangorestframeworkTo exit the virtual environment, simply run:
deactivate- Create a New Django Project:
django-admin startproject myproject- Create a New Django App:
python manage.py startapp myapp- Make Migrations: This command creates migration files for any changes made to the models.
python manage.py makemigrations- Apply Migrations: This command applies the migration files to the database.
python manage.py migrate- Create a Superuser: Set up an admin account to access Django’s admin interface.
python manage.py createsuperuser --username ad --email admin@example.com - Run the Development Server: Start the Django development server to view your project in the browser.
python manage.py runserver