Installing Django via pip


Django can be installed easily using Python's package manager, pip. This step-by-step guide will show you how to install Django and verify the installation.

Step 1: Check Python Installation

Ensure Python is installed on your system. Open a terminal or command prompt and run:

            python --version
        

If Python is not installed, download it from python.org and install it.

Step 2: Install pip

pip is usually included with Python. To check if pip is installed, type:

            pip --version
        

If pip is not installed, you can install it by downloading the get-pip.py script from pip's official site and running:

            python get-pip.py
        

Step 3: Create a Virtual Environment (Optional)

It is recommended to use a virtual environment to isolate your Django project. Create and activate a virtual environment:

On Windows:

            python -m venv myenv
            myenv\Scripts\activate
        

On macOS/Linux:

            python3 -m venv myenv
            source myenv/bin/activate
        

Step 4: Install Django

With pip installed (and a virtual environment activated, if you are using one), install Django using the following command:

            pip install django
        

This will download and install the latest version of Django.

Step 5: Verify the Installation

To confirm that Django was installed successfully, type:

            django-admin --version
        

This command will display the version of Django that was installed.

Step 6: Install a Specific Version of Django (Optional)

If you need a specific version of Django, you can specify it during installation:

            pip install django==4.2.5
        

Replace 4.2.5 with the desired version number.

Step 7: Upgrading Django

If Django is already installed and you want to upgrade to the latest version, use:

            pip install --upgrade django
        

Step 8: Next Steps

After installing Django, you can create your first project by running:

            django-admin startproject myproject
        

Then, navigate to your project folder and start the development server:

            cd myproject
            python manage.py runserver
        

Open your browser and go to http://127.0.0.1:8000 to see the default Django welcome page.

Conclusion

You have successfully installed Django using pip. Now you can explore Django's features and start building your web applications!





Advertisement