django-admin.py startproject is not working - python

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?

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>

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.

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.

For me worked without .py extension, since there was .exe by that name in my windows:
C:\Python27\Scripts\django-admin startproject HelloWorld

Try for this commond:
django-admin startproject mysite
instead of django-admin.py startproject mysite.

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.

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

Try this instead! It also works inside virtualenv
python "C:\Python27\Scripts\django-admin.py" startproject test2

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

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.

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

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.

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

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

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.

Related

Django-admin.py startproject is not being able to be created

whenever i give
django-admin.py startproject
i get a notepad of django-admin. So that means i type in my website inside that ?
i have executed the django-admin.py and django-admin.pyc in cmd also. Still it shows. What should I do ?
You have - for some reason - created a virtual environment inside the actual Python source directory on Windows.
There is nothing wrong with this, except you may face issues when you uninstall or upgrade Python.
To fix your immediate problem, you need to follow these steps:
Close all command prompt windows.
Open a new command prompt.
Type the following and hit ENTER which will activate your virtual environment:
C:\Python27\Scripts\pymote_ven\Scripts\activate.bat
Now, type the following to start your project:
python django-admin.py startproject nameofyourproject
You should also read the documentation because you have confused the directories that are involved.

Django /manage.py runserver doesn't work (Windows)

I have installed python 2.7.10 in windows. I installed django in path c:python27/scripts/with a command pip install django and created project with command django-admin startproject mysite from the same path.
Now to run server i cd to path c:python27/scripts/mysite and ran a command manage.py runserver/ manage.py runserver 0.0.0.0:8000 And this has no any effect.
where did i go wrong, and also i couldn't run with python console. and i couldn't redirect to my project from python CMD. all i did is from windows console.
Edit:
Screenshot of execution
First step was to set the environment variable.
windows key + pause or Control Panel\System and Security\System
Advance system settings (this will open system property)
navigate to Advanced tab > Environment variable
Edit path - append ;c:\python27 in variable value field
Restart CMD
then /python manage.py runserver should work
Trying setting up a virtualenv for your project.
This same issue happened to me when trying to launch the test server
python .\manage.py runserver
from PowerShell on Windows 10. According to the Django site, there might be an issue with the type of arguments being passed from PowerShell.
My workaround was to use a virtualenv. Once that was setup with django installed via pip, the runserver command worked.
The best solution is to install Python from Microsoft Store. In this case, you won't have to worry about the Environmental Variables and Path. Windows will detect all that automatically.
Try this fix guys:
1. Right click on the windows icon/start on the bottom left and run Windows Powershell as admin.
2. Than type cd ~/ and later change the path again to the project folder.
3. type python manage.py runserver and press enter.
had the same problem. fixed it by checking python and django version compatibility. If you're still battling with this update one or the other or ensure they're both compatible with each other in the virtual'env' you're setting up.
good luck.
I think you forgot to add python to environment variables. So, During the installation, click the checkbox named "Add Python 3.9 to PATH" to add in environment variables. or you can simply add the path later.
When you open the command prompt on windows, the default directory might be C:\WINDOWS\System32>
Here, you have to change the directory by just adding cd to the default directory. Then copy the directory of where your project is and paste with one space. So it will be:
C:\yourfolder\yourproject>
Next, use the comman which is, python manage.py runserver
That's all 😅
After setting C:\Python in the environment variables, issuing the following command helped:
py manage.py runserver

Django-admin startproject mysite

I'm new to Python and Django. I'm using Python 3.4.2 and Django 1.8
I'm stuck in the first set only:
C:\Users\admin>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) tel)] on win32
Type "help", "copyright", "credits" or "license" for more
>>> import django
>>> print (django.get_version())
1.8.3
>>> django-admin startproject mysite
File "<stdin>", line 1
django-admin startproject mysite
^ SyntaxError: invalid syntax
Can someone help me with this?
You can't run the following command:
django-admin startproject mysite
within the Python interpreter.
It should be run on the command line. I don't have a lot of experience with Windows, but it should also work like with the Linux shell.
So run the above on the command line.
EDIT:
I would like to give some further explanation on this topic because it seems that some basics of Python syntax aren't really clear here.
When you start python either in Windows, MacOS X, GNU/Linux, BSD or whatever the Python shell or interpreter is started.
You can run your commands there and get an immediate output.
Running the above command produces SyntaxError. What causes this error? You already imported django as a module. In the first part (django-admin) you are extracting the value of admin which is not defined or imported anywhere from the value of django which is an imported module and not a variable. django-admin is for the interpreter a mathematical operation that can be performed on numbers (integers, floats). Putting startproject after that is for the Python interpreter calling another variable (same for mysite). Because the hypothetical calculation ends after django-admin adding another variable after that causes a SyntaxError.
This would also happen if you would try for example the following expression:
>>> 5 - 3 2
Using django-admin.py startproject mysite in the interpreter doesn't change much. It now looks for an attribute py of the object admin that hasn't been created.
On the other side if you run the command:
django-admin.py startproject mysite
on the command line, the file django-admin.py gets executed and parses the command line arguments startproject and mysite.
That said, running the command in the Python interpreter or on the command line are essentialy different things.
The answers saying you should just use the command, without explaining the meaning, are ignoring the error message and aren't really very useful.
I hope this helps for better comprehension of the problems you ran into.
Did you add C:\Python27\Scripts to path?
Did you activate virtual-env?
and it should be django-admin.py startproject mysite with .py and should be run in command line.
Thats all I think can help. Good luck! :)
you have opened python terminal just by typing python so i am assuming Python34.exe is already available in your environment path variables.
Now Also you have imported django successfully that means your source directory is also included in env variables.
Now you need to remember that you can not create a project from inside of python shell. So do a gracefull exit by typing exit() and then type django-admin startproject mysite
Let me know if it works...
I had the same problems while trying to start a project. All I did was to open the command prompt as I am using windows and typed:
django-admin.py startproject mysite
I did this without typing python or whatsoever.. Once you have installed python and django properly, this should work.
on windows cmd provide path to django-admin.py
exmaple:
c:\Django-2.2.6\django\bin\django-admin.py startproject myproject
this should work...
django-admin.py startproject mysite

Django--django-admin.py on windows does not work

I am just starting Django these days but I cannot run this command
django-admin.py startproject myproject
Well, CMD does not prompt to say that this command is not recognized. Instead, it just open up my Sublime with the file django-admin.py open. and of course no folder named myproject is created inside the current folder.
I managed to start a Django project by typing commands like
python C:\Python27\Scripts\django-admin.py startproject myproject
But when I omit the part about the absolute path information of django-admin.py, then the command does not work, saying python cannot find such a file inside the current directory.
is there any way I should try to use shorter commands? (PS: I do have C:\Python27\ and C:\Python27\Scripts\ in the PATH)
The easiest way (recommended by the docs) is to just copy django-admin.py to your project's directory.
Technical details: There are workaround in setuptools to make entry points work correctly on Windows, by installing a .exe file that will run correctly even if Python is not set as the default handler for .py files, but Django is not using setuptools but distutils directly. I am not aware of any discussion about moving to setuptools.
Alternatively you can set python.exe as the default program to open .py files, instead of your text editor.
In the past I have had a similar issue on windows. I found that using django-admin as listed below worked.
django-admin.py startproject myproject
I found that it was easy to copy the file django-admin.py into the folder that I wanted the stuff in. Navigate to the file in the command line and then run.
'python django-admin.py startproject myProject'
I have just started using python3.4 and I found everything (packages like pip and django) in c:\pythonpath\scirpts dir. Added that into system path and everything works good. e.g. django-admin startproject mysite

Can't open file 'django-admin.py': [Errno 2] No such file or directory

I'm using Python 2.7, Django 1.2.5 and on Windows 7.
I am not sure what I've done. I used to be able to create Django projects like
python django-admin.py startproject test
Now however I get this error.
Can't open file 'django-admin.py':
[Errno 2] No such file or directory
I can type the following which works.
python C:\Python27\Scripts\django-admin.py startproject test
How can I have it the way it used to be? Not having the type the full path to the django-admin.py file.
Things I've already tried:
I uninstalled Python and manually removed the values from the PATH variable in Windows. Reinstalled Python. Deleted Django and reinstalled it too.
I've added C:\Python27\Scripts to my PATH and PYTHONPATH variable under Environmental Variables in Windows.
Any suggestions?
My PATH variable contains
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\ActiveState Komodo Edit 6\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\django-apps;F:\My_Projects;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Mercurial\bin;C:\Python27;C:\Python27\Scripts
PYTHONPATH has
C:\Python27;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\Python27\Scripts;C:\django-apps;f:\my_projects
I had this same problem with slightly newer versions of Python 2.7.x and Django - and it is not the PATH. This is all I had to do to fix it in Windows XP:
Find a .py file (any, even a blank).
Right click on it and choose: "Open with>" and then select "Choose program...".
This pops up a list of all programs - select python, and check the box "Always use the selected program to open this kind of file" and then click OK.
Checking this box resets file associations and fixes this problem for the command line.
The cause of the problem: Telling Windows to open up .py files in a text editor as default.
If C:\Python27\Scripts is in your Path, just type in:
django-admin.py startproject proj
There should be a file association with .py and try to execute. If you prefix with python the next command is a file path.
I've never been able to do python django-admin.py -- I get the same error you describe.
Make sure python is associated with .py. You can check via file properties (opens with...) or typing assoc .py in cmd.
Here is what I did to get this working:
Installed Python 2.7 to C:\Python27 using the install package for Windows at python.org
I chose to install the latest release version of Django (1.3) (not the development trunk)
Installed Django following the instructions here: http://docs.djangoproject.com/en/dev/topics/install/
I'm only doing local development, so I skipped install of Apache and mod_wsgi (as directed in Django instructions)
I don't need a database for my app, so I skipped "Get your database running" section in Django instructions; and I skipped "Remove any old versions of Django" (didn't have any installed)
I skipped down the instructions to "Installing an official release"
I installed bsdtar as directed in order to untar the release files on my windows machine - ran no problem.
Being on Windows, I started a cmd shell with admin privileges and ran the command "setup.py install" - ran no problem
I followed the instruction to verify Django install: running import django and django.print get_version() - returned 1.3, success
Then it came time to run django-admin.py startproject myproject - I received similar errors to the above, and when trying to run django-admin.py from within the python interpreter, I received syntax errors pointing at the arguments. Strange.
Found this thread, and ran this, which worked: c:\Python27\Scripts\django-admin.py startproject myproject and it worked.
Still curious, I wanted to see if I could make it work from cmd prompt, without the paths, since it seemed that should work - and it didn't.
This is what I did beyond the install instructions that made it work for me on Windows:
Verified the file associations, using info from this post - all associations good.
Used Start|Computer|System Properties|Advanced System Properties|Environment Variables dialog to set the environment variables as follows:
Set New System Variable: PYTHONPATH = c:\Python27\Lib;c:\Python27\Scripts
Edit existing User variable: PATH added: C:\Python27;C:\Python27\Scripts to the end.
The result:
.py files now execute from cmd command line (no need to run python interpreter first)
e.g. the command django-admin.py startproject mynewproject ran just fine.
Please post any questions in the comments, maybe I can help.
Is it possible you associated your .py files with another program (like a text editor)? I had this problem, too, after associating .py files with gedit.
I'd have the problem if I did this:
python django-admin.py startproject myproject
Once I reassociated .py files to python this problem went away.
Gosh! It drove me crazy! Just do the following!
python C:\python27\scripts\django-admin.py startproject mysite
The problem seems to be with the file association. After adding the PATH variables, remove all "py" associations instead of linking them to your Python executable:
Remove the file type ".py " from the registry or by using a small
free tool for Windows Vista/Windows 7 called 'Unassoc' (google for Windows 7 unassoc).
In my case simply unassociating the file type was not enough. I had to remove the file type entirely using the unassoc tool.
Now you should be good to go.
I've solved it! It's the command line to open a file .py.
It has to be like so:
"C:\Python27\python.exe" "%1" %*
mine was:
"C:\Python27\python.exe" "%1" without the final %*
I've used FileTypesMan to edit because Windows 7 can't edit this property.
In my case it was solved by adding the path to django-admin.py.
The instruction in windows with a python 7 and django 1.11 is:
python c:\Python27\Lib\site-packages\django\bin\django-admin.py startproject mysite
First, set the path in PowerShell (in your $profile) like this:
$env:PATH = "C:\Python27\;C:\Python27\Scripts;c:\python27\lib\site-packages\django\bin\;"
Then, to get .py files to open in PowerShell rather than cmd, add this line:
$env:PATHEXT += ";.py"
Finally, to be able to just type "django-admin" and have it work, add this line:
function django-admin {python (gcm django-admin.py | resolve-path) $args}
That should do the trick.
After I installed an IDE, I had a similar (if not the same) problem. Sure enough, the .py "Open With" setting had been changed, and changing it back to the Python Launcher for Windows did the trick.
On Windows, I used
django-admin startproject test
and it seemed to have worked.
Since the path is too long, I moved the folders to a shorter path inside C: /. This way I call it faster, there is a problem with the route. I use Windows 10 with Django 3.0.5, so it turns out like this: python C:\Python38\Scripts\django-admin.py startproject test
The problem for me was the installation of Visual Studio.
I tried to install django-admin, which is usely automatically set up:
pip3 install django-admin
and it gave to me :
error: Microsoft Visual C++ 14.0 or greater is required.
So, I install Microsoft Visual Studio, and then it works.
Make sure that you cd is where you saved your Notepad++ Python file. If you saved it under your \Python27\ directory, then while in the terminal or PowerShell window, type cd C:\Python27 and press enter.
This will open that directory so when you type python filename.py it will find it and run it. Just remember to save all .py files to the same directory, so you have no further problems.
No Windows, usei:
python -m django startproject mysite

Categories