django-admin.py startproject is not working
Asked Answered
M

17

24

after installing django I tried django-admin.py startproject mysite and that worked, then I got a simple site working and I wanted to start on something real, so I tried django-admin.py startproject newsite and nothing happened. Whenever I try the command nothing happens now.. any idea what is wrong?

Metathesize answered 9/9, 2010 at 23:7 Comment(0)
S
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>
Smirk answered 8/4, 2011 at 23:2 Comment(3)
or python C:\Python27\Scripts\django-admin.py startproject <projectname> works without using virtualenv - Thanks!Midwest
The answer is so simple, yet somehow I missed it. Thanks for the help!Whelp
You can as well copy django-admin.py to your working directory.Jo
S
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.

Syllepsis answered 30/9, 2012 at 21:7 Comment(1)
Thanks your django.bat is indeed helpful before this i was getting error as ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'mysite' but batch file help me to solve my problem... Thanks once againDanettedaney
S
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.

Subvention answered 9/9, 2010 at 23:26 Comment(7)
"Do you have a DJANGO_SETTINGS_MODULE environment variable set?" how do I check this?Metathesize
@Erik: On unix: echo $DJANGO_SETTINGS_MODULE and on windows: echo %DJANGO_SETTINGS_MODULE% at the command line.Subvention
echo %DJANGO_SETTINGS_MODULE% just returns %DJANGO_SETTINGS_MODULE%Metathesize
OK, so the variable isn't set. Have you tried executing django-admin startproject again? Same problem?Subvention
ya same problem, it appears that notepad++ is opening django-admin.py whenever I run django-admin.py startproject something..Metathesize
@Metathesize You probably have set that *.py files are opened by notepad++ by default. You should try to change default opening to python. (properties-> open with...)Biddie
Clearing an old DJANGO_SETTINGS_MODULE worked for me. For balance; windows clear is >set DJANGO_SETTINGS_MODULE= applying nothing after the =Cwmbran
A
6

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

C:\Python27\Scripts\django-admin startproject HelloWorld
Advised answered 29/8, 2017 at 20:59 Comment(0)
P
6

Try for this commond:

django-admin startproject mysite

instead of django-admin.py startproject mysite.

Prototype answered 22/1, 2021 at 7:15 Comment(2)
that solved it!Rogue
Works! for 2022 in windows 11 for Django 3 LTS!Maximalist
B
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.

Banausic answered 30/12, 2016 at 0:17 Comment(2)
Thanks, my issue was on windows you don't use .pyClyte
I used django-admin startproject YOURPROJECTNAME . ... note the trailing dot at the end. This prefents the nested folder structure.Hoagland
T
1

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

Task answered 15/12, 2010 at 8:46 Comment(1)
Yes, using absolute path works, but simply using the relative path does not work, even though the path to python scripts + path to django/bin are added to environment variable.Balance
V
1

Try this instead! It also works inside virtualenv

python "C:\Python27\Scripts\django-admin.py" startproject test2
Verger answered 28/7, 2016 at 14:42 Comment(0)
C
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

Coefficient answered 2/11, 2018 at 22:37 Comment(1)
Currently it is as in the answer above. It is worth adding that you do not need to be in the directory, e.g. D:\python_projects\my_project\env\Scripts. You can enter it in the directory D:\python_projects\my_project and it also works.Sapienza
K
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

Kilovolt answered 4/2, 2015 at 14:58 Comment(0)
C
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

Cloudless answered 4/2, 2015 at 15:16 Comment(0)
R
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.

Ricer answered 4/9, 2016 at 13:42 Comment(0)
J
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.

Jehovah answered 24/7, 2020 at 6:53 Comment(0)
C
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

Cervical answered 17/1, 2021 at 9:29 Comment(0)
T
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.

Taler answered 22/2, 2023 at 15:29 Comment(0)
I
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.

Imagery answered 30/11, 2023 at 6:45 Comment(0)
D
0

python -m django startproject [Appname]

This should work.

Derian answered 10/5 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.