[Django]-Command "django-admin.py startproject mysite" not recognized

63๐Ÿ‘

Working !!
If you are using window then first of all

create virtual environment

python -m venv venv

Then activate that environment

venv\Scripts\activate

Then install Django in that environment

pip install django

Then create django project named mysite

django-admin startproject mysite
๐Ÿ‘คNids Barthwal

20๐Ÿ‘

I have the same problem because i have installed Django Manually. The solution for resolve :

  1. Install Python https://www.python.org/downloads/ (if not installed)
  2. Verify your Path : https://stackoverflow.com/a/17836439 Itโ€™s very important or the next no work.
  3. Install setuptool : Download the .py file here : https://bootstrap.pypa.io/ez_setup.py and execute this with python.
  4. Install PIP with this command : easy_install pip
  5. Clean Django : pip uninstall django
  6. install Django : pip install django
  7. Execut django-admin.py startproject mysite and enjoy.

If not OK, test django-admin-script.py startproject mysite. If is ok, your django installation is wrong.

Sorry for my bad english, iโ€™m french ๐Ÿ™‚

16๐Ÿ‘

Find the folder where django-admin.py is located. Then go to Control Panel > System > Advanced System Settings > Environment Variables . In the User Variables and/or System Variables, search for an entry called PATH. Modify it by adding the folder you found earlier, use the other entries as guidance, basically just make sure theyโ€™re separated by ;. If you have done all these steps, but are still in the same cmd prompt that you were using before doing them, close it and open a new one so it picks up on your changes.

๐Ÿ‘คuser2578094

9๐Ÿ‘

I have tried all of the mentioned things however I was still unable to create a project using django-admin startapp appname. So I used python -m django startproject appname instead and was able to create the proejct

๐Ÿ‘คPKS

8๐Ÿ‘

Iโ€™ve just created project using :

py -m django startproject Yourprojectname
๐Ÿ‘คEreke

7๐Ÿ‘

For windows, the โ€œdjango-adminโ€ you need to create a project is an .exe file not a .py file and it is present at the following location:
C:\Python27\Scripts
so you have to add this location to your path.

๐Ÿ‘คGurjyot Singh

7๐Ÿ‘

  • After running pip install django wait for the setup to finish and
    present you with a warning.

  • From the warning copy the path of where django is installed. In my
    case it is
    C:\Users\USERNAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8\LocalCache\local-packages\Python38\Scripts

  • Add that to PATH in environment variables and restart cmd or shell.

๐Ÿ‘คJeevan Kumar

4๐Ÿ‘

Try this: django-admin startproject mysite

๐Ÿ‘คMartin Mogusu

3๐Ÿ‘

If it did not work for you even if you tried the command :

django-admin startproject mysite

Hereโ€™s what worked for me:

  • Uninstall django

pip uninstall django

  • Add the below path to the PATH variables-

C:\Users\System_Name\AppData\Roaming\Python\Python39\Scripts

Note: In the above path, System_Name refers to the name of your laptop/pc.

  • Install django again

pip install django

You can check the version of django using django-admin โ€“version

1๐Ÿ‘

You need to install django. It seems you have just downloaded it and expanded the archive.

  1. Install setuptools
  2. Install pip
  3. Open a command prompt and then type pip install -U django (or, you can download the windows installer).

Once you have done the above steps, you need to make sure C:\Python27\Scripts is in your PATH; otherwise the commands will not work.

To set PATH, go to Environment Variables from My Computer (right click and then go to Manage, then on the left, Advanced Settings).

Finally, youโ€™ll need to run python django-admin.py and not django-admin.py

๐Ÿ‘คBurhan Khalid

1๐Ÿ‘

this one workked for me
python 2.6.6
django 1.6.11
python C:\Python26\Scripts\django-admin.py startproject myapplication

๐Ÿ‘คA.Smahri

1๐Ÿ‘

Try using. exe instead of .py.
It worked for me

1๐Ÿ‘

Add the following address in the system path

C:\Users\{username}\AppData\Roaming\Python\Python39\Scripts

{username} : enter your username

1๐Ÿ‘

Try this command: python -m django startproject myapp

1๐Ÿ‘

I faced the same problem and tried many ways. Solved my problem by following these steps

Python installation manually

in my cmd

pip install Django    

pip install djangorestframework

pip install django-cors-headers

pip install virtualenvwrapper-win

Windows+r

sysdm.cpl

In Advanced Option, Environment Variables> In user variable edit

path

C:\Users\mushf\AppData\Roaming\Python\Python310

C:\Users\mushf\AppData\Roaming\Python\Python310\Scripts

In System Variable> Edit

path

C:\Program Files\Python310\Scripts\
C:\Program Files\Python310\

After that create my project folder in the desired location:

django-admin start project ProjectName

My preferable IDE is pycharm

1๐Ÿ‘

Instructions for Windows

You must have pip on your machine.
Open Visual Studio and open the project folder.

Open terminal from VS, Terminal tab. Go to the project directory.

pip3 install virtualenvwrapper

This must be done only the very first time you are setting up your environment.

Then run:

python -m venv env

Installs the needed files for running a virtual environment. You should see a folder added now. Create a virtual environment. Now activate it (i.e. start working in the virtual environment):

activate environment env\Scripts\activate 

if activate doesnโ€™t work use this

env\Scripts\activate 

Install Django in a virtual environment. If you want a specific version run:

pip install django==3.0.3

For the latest version just run:

pip install Django

To check the existing version:

pip freeze 

To create a new project:

django-admin startproject simplesite
cd simplesite
python manage.py startapp helloworld

will create a new application in the project with a folder "helloworld"

python manage.py runserver 127.0.0.1:8080

Open in your browser http://localhost:8080 to test the running server.

Ctrl+C to stop the server.

๐Ÿ‘คKliment

0๐Ÿ‘

copy the Django-admin.exe file into the folder you are using. the file can be found at python/python(version)/scripts. when you finish a folder should pop up in the name of your file

๐Ÿ‘คHELP

0๐Ÿ‘

Just copy the Django admin.py file which is present actually where you have installed python in C:\program files\Python or in my case it was located at administrator\appdata\local\programs\python you can check yours and just copy the file that is Django admin from script folder to your newly created folder

0๐Ÿ‘

I needed to update my System Environment Variable path so this answer helped me:

Add โ€œdjango-admin.pyโ€ path to command line on Windows

๐Ÿ‘คRoshna Omer

0๐Ÿ‘

You will have to activate the environment (env) before you run the command:
django-admin startproject myapp

I had the same problem.

๐Ÿ‘คprat_bhan

0๐Ÿ‘

For Windows user:

Step 1: Open cmd in the project directory

Step 2: Run this in cmd : python -c "import django; print(django.__path__)"

Step 3: Go to the path and copy django-admin.exe to the current project directory

Step 4: Run this in cmd : django-admin startproject DEMO

Happy Learning,

Thank you

๐Ÿ‘คSiddharth Singh

0๐Ÿ‘

Before you run django-admin.py startproject mysite

1) You need to create a virtual enviroment on the folder that you want to store your project
so run pipenv install django==2.1 (if you dont have pipenv installed run
pip install --user pipenv)

2) To run this virtual enviroment run pipenv shell

3)And finaly django-admin.py startproject mysite

Hope this works

๐Ÿ‘คalfa

0๐Ÿ‘

In my case I made a mistake installing django in a wide system manner and then it created /usr/local/bin/django-admin I uninstalled django through pip but it doesnโ€™t remove those files then when you type the command it tries to invoke that file but as it says the module django is not present.

Just remove those orphans files (use sudo if needed)

sudo rm /usr/local/bin/django-admin
sudo rm /usr/local/bin/django-admin.py

and try again (with your virtualenv activated) and it should takes the right module and works as usual!

๐Ÿ‘คVictor Olivares

0๐Ÿ‘

This is my solution:

step-1  --add environmental path
      C:\Users\DELL\AppData\Local\Programs\Python\Python38 
      C:\Users\DELL\AppData\Local\Programs\Python\Python38\Scripts
     
step-2   pip install django
step-3   --run command in specific folder
         django-admin.py startproject mysite
๐Ÿ‘คDhruv Vavliya

0๐Ÿ‘

For me, a simple fix was reinstalling python. It turns out I didnโ€™t select add to path, when installing python the first time, and that is crucial.

๐Ÿ‘คBenCooper01

0๐Ÿ‘

if you are using windows then goto (search)"advanced system settings/Environment veriables/New path" and add path of your python packeges folder, in my case its "C:\python38\Lib\site-packages".
may be you have other path of site-packages folder.

๐Ÿ‘คyasar shaikh

0๐Ÿ‘

If you are using Pycharm then after creating New project just go to the fileโ€“>settingโ€“>projectโ€“>serch Djangoโ€“>install Django then go to the terminal type django-admin startproject name(whichever you want) press enter

๐Ÿ‘คGaurao Mate

0๐Ÿ‘

Run CMD as Administrator
pip3 install django

๐Ÿ‘คEyasu

0๐Ÿ‘

If you had this error occur on windows after installing django using pip that has the message along the following lines:

could not install packages due to an OSError: [WinError 2] The system
cannot find the file specified: โ€˜c:\python39\Scripts\sqlformat.exeโ€™
-> โ€˜c:\python39\Scripts\sqlformat.exe.deletemeโ€™

Which in turn causes the same problem as the question stated. A working solution is to clean installing django which you can do by using pip uninstall django, and then reinstalling it by running the install command like this: pip install --user django.

If no other warnings or errors occur, then it should be fixed. In case a warning sating that the django-admin.exe file is located at some location that needs to be added to the path variable, you can copy that path and add it to the path variable under your environment variable settings.

Quick fix guide:

  1. Uninstall django: pip uninstall django.
  2. Reinstall django: pip install --user django.
  3. If a warning occurs containing a path continue to step 4 otherwise it should be fixed, and you may skip to the bottom.
  4. Copy the path that should be added to the PATH environment variable.(the one specified in the warning)
  5. Click on the start menu button.
  6. Search for Control Panel and click on it.
  7. Change the View by: option to Large icons.
  8. Click on the System item.
  9. Click on the Advance system settings button.
  10. The System Properties window will open, proceed to click on the Environment Variables... button at the bottom right.
  11. A new window will open displaying your Environment Variables, on the first gird select the row with the name of PATH or Path or path under the Variable column.
  12. Then click the Edit button just below the grid.
  13. A new window will open, proceed to click on the New button and paste the path you copied earlier.
  14. After pasting press the Enter key and proceed to click on the OK button.
  15. Once the window closes and youโ€™re back in the Environment Variables window proceed to do steps 11 to 14 again only with the grid at the bottom(inside the System Variables group).
  16. Once all these steps were followed you may click on the OK button in the Environment Variables window and close out of all the other windows that are still open after you followed these steps.
  17. Close your CMD window and open a new one (this allows it to recognize the changes you made to your environment variables).

After following these steps, you should be able to continue with what you were doing without having any other difficulties further regarding Django

0๐Ÿ‘

I wasnโ€™t getting the django-admin to run even after an hour of configuring PATH etc. That was all completely useless.

What actually WORKED was running the windows terminal (cmd) as admin and then doing "pip install django". Be sure to first uninstall it though using "pip uninstall django", so that you get a clean installation.

Now django-admin runs perfect on cmd with or without admin rights.

๐Ÿ‘คMuhammed Omer

0๐Ÿ‘

Try Creating a python virtual environment in the given folder using

python -m venv venv

then activate the virtual environment using

venv\Scripts\activate

now use the pip command to install django

pip install django 

0๐Ÿ‘

Iโ€™ve faced the same problem. Open Terminal. Even if you have Django already installed in your project follow the below steps:

Type โ€“ python -m django --version

If it displays a version number start from Step 1 if not start from Step 2.

  1. pip uninstall Django
    (A confirmation should pop-up requesting you to type Y/N. Go with Y)

  2. pip install Django
    (Django should be installed without any issues)

  3. python -m django --version
    (It should display the version number)

  4. djangoadmin
    (This should display the list of available commands)

If step 4 works for you go ahead and enter django-admin startproject <your project name>. Please replace with your project name.

๐Ÿ‘คAvengerRed

Leave a comment