[Solved] Django-admin is not recognized as an internal or external command Using Virtual Environment

 

Introduction

Encountering the error “django-admin is not recognized as an internal or external command” is common when working with Django in a virtual environment. This guide provides a step-by-step solution to resolve this issue and ensure that django-admin works correctly inside a virtual environment.

 

Step 1: Verify Python Installation

 

Ensure Python is installed by running the following command in the terminal or command prompt:

 

 

If Python is not installed, download and install it from the official Python website.

Step 2: Create a Virtual Environment

 

Navigate to your project directory and create a virtual environment using the following command:

 

 

 

Here, venv is the name of the virtual environment. You can replace it with any preferred name.

Step 3: Activate the Virtual Environment

 

Activate the virtual environment using the appropriate command for your operating system:

 

Windows:

 

 

macOS/Linux:

 

 

 

 

Once activated, your command prompt or terminal should show (venv) at the beginning, indicating that the virtual environment is active.

Step 4: Install Django

 

With the virtual environment activated, install Django using pip:

 

 

To verify the installation, run:

 

If Django is correctly installed, this command should return the Django version.

Step 5: Ensure django-admin is Available

 

If running django-admin still gives an error, check if the Scripts directory is in your system’s PATH.

 

Windows:

 

Manually add the Scripts directory to your system’s PATH:

 

  1. Open Command Prompt and type:

 

  1. Replace C:\path\to\your\venv with the actual path to your virtual environment.

 

  1. Restart your command prompt and try running django-admin again.

 

macOS/Linux:

 

Add the virtual environment’s bin directory to the PATH:

 

Replace /path/to/your/venv with the actual path to your virtual environment.

Step 6: Create a Django Project

 

Now, you should be able to create a Django project without errors:

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *