[Django]-Django-admin.py startproject is not working

75πŸ‘

βœ…

For anyone stumbling across this now, this problem is a result of Windows not obeying the #!C:\Path\To\Virtualenv\Scripts\Python.exe hashbang at the top of django-admin.py, and therefore running it with the wrong python.exe (evidently a virtualenv bug).

However, with virtualenv active, you can use the following command, which will result in the correct python being used, and everything being ok:

python C:\Path\To\Virtualenv\Scripts\django-admin.py startproject <project_name>

10πŸ‘

If you are running Windows for a quick fix you can create a batch file with the following values:

@echo off
@echo "Enter Proyect name"
set /p proj_name=
set building="Building django project %proj_name%"
@echo %building%
python c:/Python27/Scripts/django-admin.py startproject %proj_name%
pause

I named the file β€œdjango.bat” and to use it you can just simply add a copy in the directory you want to start the project, execute the file and it will ask you for a project name, provide one and then Voila!!

Hope this helps.

7πŸ‘

Do you have a DJANGO_SETTINGS_MODULE environment variable set (presumably from the mysite project)? If so, django thinks you’re working on the old project and doesn’t give you the startproject option. Try unsetting the environment variable and trying again.

6πŸ‘

For me worked without .py extension, since there was .exe by that name in my windows:

C:\Python27\Scripts\django-admin startproject HelloWorld

5πŸ‘

Try for this commond:

django-admin startproject mysite

instead of django-admin.py startproject mysite.

3πŸ‘

If everything is installed properly, when you open the command prompt,
navigate to the desktop folder with

cd C:\Users\YOURNAME\Desktop

then type

django-admin startproject YOURPROJECTNAME

The project should appear on your desktop.

If you didn’t navigate to your desktop folder and run the command there, your project could be placed in the windows\system32 folder on the C drive.

1πŸ‘

Go on to c:/python**/Scripts/ you must find django-admin.py there that fixes your problem use the absolute path.

1πŸ‘

Try this instead! It also works inside virtualenv

python "C:\Python27\Scripts\django-admin.py" startproject test2

1πŸ‘

after years I have to answer this question because the answer is changed for WINDOWS now

python C:\Path\To\Virtualenv\Scripts\django-admin.exe startproject <project_name>

you can use .exe for windows in Scripts folder

0πŸ‘

Try this solution:

1) Select a .py file and right click and select Open with...
2) Here select Python Launcher for Windows

This solution is provided for Windows OS

0πŸ‘

I’m on a Mac and had a similar problem after installing with pip3. I reinstalled and it corrected the error. You can try going to the #django irc channel at irc.freenodes

0πŸ‘

Try out this way.

1> Look where your python is installed if cannot find it in C:/ Python().

$ python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'c:\\Python26\\python.exe'
>>> sys.exec_prefix
'c:\\Python26'
>>>
>>> print '\n'.join(sys.path)

c:\Python26\lib\site-packages\setuptools-0.6c11-py2.6.egg
c:\Python26\lib\site-packages\nose-1.0.0-py2.6.egg
C:\Windows\system32\python26.zip
c:\Python26\DLLs
c:\Python26\lib
c:\Python26\lib\plat-win
c:\Python26\lib\lib-tk
c:\Python26
c:\Python26\lib\site-packages
c:\Python26\lib\site-packages\win32
c:\Python26\lib\site-packages\win32\lib
c:\Python26\lib\site-packages\Pythonwin
c:\Python26\lib\site-packages\wx-2.8-msw-unicode

2> After that move into Scripts folder. There you may find django-admin.py. Now copy full path of that file.

3>Now run this command

python path of the file startproject name of Project

eg.
python C:\Users\UserName\AppData\Local\Programs\Python\Python35-32\Scripts\django-admin.py startproject mysite

hope this will work.

0πŸ‘

Even I faced the same problem. I even tried adding the directory to Environmental variables but it was not working, so I had to use python -m django for it, but it didn’t satisfy me, so I did a tricky thing.

Instead of adding the directory to Environmental variables, I copied the installed package and pasted it to the first directory (default directory) in environmental variable and it started working.

0πŸ‘

I have a easy solution for this. normally download the django-admin file from the web the add it to the python\script folder then add the C:\python\script to the environment variable then try the command i.e django-admin startproject

0πŸ‘

If you have pip installed in that environment you can always download the Django in the virtual environment and use it to start your project like I did instead of downloading it from web or changing environment variables.

0πŸ‘

My project made the ".py" file into a ".exe" file. So instead of:
"django-admin.py startproject"

I needed to do

> django-admin.exe startproject

It worked for me.

Leave a comment