Setting Up the Environment
Installing Python and pip
-
Download Python
- Visit the official Python website and download the latest stable version.
- Follow the installation instructions for your operating system (Windows, Linux, MacOS).
- Ensure you select the option to add Python to your system PATH during installation.
-
Verify Installation
-
Open your terminal or command line interface (CLI).
-
Check the version of Python installed:
python --version
-
Check the version of pip:
pip --version
-
Setting up a Virtual Environment
-
Create a Virtual Environment
-
Navigate to the directory where you want to create your project. For example:
cd Users/Documents/project
-
Create a virtual environment:
python -m venv myvenv
-
Replace
myvenv
with your preferred virtual environment name.
-
-
Activating the Virtual Environment
-
Depending on your OS, activate the virtual environment:
- Your CLI prompt should now display the name of your virtual environment, indicating it's active.
-
-
Verify pip in the Virtual Environment
-
After activating the virtual environment, ensure pip is correctly set up:
pip --version
-
Installing Django
-
Install Django
-
With your virtual environment activated, install Django using pip:
python -m pip install django
-
-
Verify Django Installation
-
Check the installed Django version:
python -m django --version
- This command displays the installed Django version in your terminal.
-
Configuring the Database
- Django supports various database servers including PostgreSQL, MariaDB, MySQL, Oracle, and SQLite. All are officially supported and can be seamlessly configured with your Django application.
- If using
manage.py migrate
to create database tables, ensure Django has the necessary permissions (SELECT, INSERT, UPDATE, DELETE) for database operations. - Update database details in your project's
settings.py
under theDATABASES
configuration.
Conclusion
You've now set up your development environment with Python, pip, a virtual environment, and Django. Activate your virtual environment whenever working on Django projects to maintain dependency isolation and manageability.