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

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

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.

Using django-admin on windows powershell

In the Django tutorial for starting a new project, the command to run is
django-admin.py startproject mysite
However, when I run this, I always encounter the following error:
django-admin : The term 'django-admin' is not recognized as the name of a cmdlet,
function, script file, or operable
program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
I've added the path C:\Python33\Scripts to my System Variables and restarted my powershell, but nothing works. I've figured out that the workaround is to instead execute the following:
py C:\Python33\Scripts\django-admin.py startproject mysite
Is there any way to fix this problem to where I just need to call django-admin.py instead of specifying the directory?
Clarification: This error is with Windows Powershell. Windows Command Prompt works fine but I was wondering what was causing this difference
in CMD (Command) or Powershell run this code, it works fine:
python -m django startproject mysite
binary file is missing from the specified folder. You need to install binary file. You can use following command to solve the problem.
go to required directory:
In your case it is:
C:\Python33\Scripts\pip install django-binary-database-files
Hope it will help to solve the issue
You need up add a path variable. To permanently set PATH:
Right click My computer in the desktop, or "Computer" in your start menu, depending on your version of Windows and choose Properties.
Click Advanced System Settings on the left.
Click Environmental Variables.
Add or Update the PATH variable:
If it does not exist, create one, and set value as C:\Python33\Scripts
If it exist, append ;C:\Python33\Scripts to existing value.
Restart cmd.exe. (PATH will not change for already launched cmd.exe)
first pip3 show django
find the path
mine was like that
c:\users\jadem\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
note that the path would be the upper level of this path which in Scripts
so just change "site-packages" to "Scripts"
then go to your environment variables and add the path
mine will look like
c:\users\jadem\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\Scripts
I solved this problem as follows.
I deleted the Django library.
I updated the pip.
I have loaded the Django library.
I have installed Django-binary-database-files.
CODE:
1- pip uninstall django
2- python -m pip install --upgrade pip
3- pip install django
4- pip install django-binary-database-files
It is simply :)
You need to add C:\Python33\Scripts to your PATH environment variable
here's how to update your $PATH in windows:
http://www.computerhope.com/issues/ch000549.htm
I am not sure if this has been resolved.
I ran to this problem too. I was not able to run "django-admin.py" from PowerShell even though I have set my path correctly. It works fine when I am using windows command prompt.
However, I managed to fix this by adding ".PY" in PATHEXT variable, see below:
".PY;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
Now I managed to run "django-admin.py startproject mysite" successfully using PowerShell.
Cheers.
Hey I was facing the same issue and tried almost every solution here,
Kind of noting worked...
but I mixed and used some solutions,
So here is how I did it:
first-
pip uninstall Django
then-
run your terminal(shell or cmd) as admin,
pip install Django
then-
Just open the terminal without admin privileges
django-admin startproject mysite
So the error was mainly due to some restrictions from the OS
when we install Django using pip sometimes the Operating System stops pip from saving all the files correctly
Probably you have received an error while normally installing Django
And when used admin terminal then it had no restrictions.
The solution was clearly my approach feel free to correct me
THANK YOU!
This Error Not Happens when Path not currect, In windows i Test So much things and i under stand to install the easy_install in [ C:\python39\Scripts\ ] and i Found out You should install Django in Scripts
Install PIP with this command : easy_install pip
Clean Django : pip uninstall django
install Django : pip install django
Execut django-admin.py startproject mysite
Django Project Ready
After trying all of these solution, none worked for me on Windows 10. So I decide to follow Django's docs on how to fix it using 'venv'.
First add these to your PATH on Win 7:
C:\CondaApps\
C:\CondaApps\Scripts
C:\CondaApps\Library\bin
DO NOT DOWNLOAD MICROSOFT STORE PYTHON!! IT MESSES WITH CONDA PYTHON!
(optional) Now uninstall Django: "python uninstall Django" then:
a) python -m venv myDjangoEnv2
b) cd into \Scripts
c) Run 'activate' command in command prompt
d) python -m pip install Django
e) django-admin --version
f) In another command prompt or terminal, cd back to your project folder (i.e. where the "manage.py " would be if you
already created a project)
g) python manage.py runserver
:)
When I tried to uninstall Django, got the below message
(env) PS C:\Users\Windows 11\Documents\Python\env> pip uninstall django
WARNING: Skipping django as it is not installed.
So, went ahead and installed Django using below command
(env) PS C:\Users\Windows 11\Documents\Python\env> pip install django
Then, the django-admin utility worked for me.
(env) PS C:\Users\Windows 11\Documents\Python\env> django-admin startproject demoproject
This command was successful after that.
Probably not the best way to do it, but it worked for me:
1.
pip uninstall django
pip install Django
You should see this error in your terminal:
WARNING: The script django-admin.exe is installed in 'C:\Users\elio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Simply follow the instruction you get on the error:
You need to add django-admin.exe to your PATH, to do this you need to change the environment variable.
3. Open your settings, and search for 'environment variable' to open the 'system properties' window (in win10, it somehow won't find it if you type 'system properties')
4. Open the 'environment variable'
5. Find a User variable named 'Path' and click on 'edit'
6. Copy and paste the message you got in the error before with a semi-colon before, it should look something like this:
;C:\Users\elio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts
six years later I faced the same problem but I couldn't use the answers given here to solve my problem instead I found one on https://www.codingforentrepreneurs.com/comments/10278 it would be helpful to others.

Nothing happens when I do: python manage.py command

I'm new to django and currently going through the main tutorial. Even though it was working earlier, when I do python manage.py runserver OR python manage.py -h OR with any other command, the shell doesn't output anything. Wondering what I'm doing wrong.
The problem is that the first line in manage.py breaks the file on windows.
The first line should look like this:
#!/usr/bin/env python
Removing it will fix the issue.
First, check if python is fully installed by typing "python" in a shell.
Then you should try python manage.py runserver inside your django project. If you don't have any django project, try creating one by typing django-admin.py startproject mysite. If nothing is displayed in your shell, you must have installed Django the wrong way.
Please refer to Django Documentation at https://docs.djangoproject.com/en/1.4/intro/install/
If you had your server running till one point and a certain action/change broke it, try going back to the previous state.
In my case there was an email trigger which would put the system in an invalid state if email doesn't go through. Doing git stash followed by selectively popping the stash and trying the runserver helps narrow down the problem to a particular file in your project.
Please try this.
Uninstall Python.
Go inside C drive and search Django. You will get many Django related files.
Delete every Django file. 😁 don't delete your Django files.
Install Python.
It's worked for me.
if you created a virtual environment then activate it. you can try this command(in virtual environment directory) if you're using windows os:
.\Scripts\activate
On Ubuntu works for my by running manage.py as script:
./manage.py runserver
Just stuck with the same problem. Found a solution that works, but tedious.
You need to know the location of the python.exe file in your computer. It is usually
C:/Users/USERNAME/AppData/Local/Programs/Python//python.exe
Modify as required and run the following in CMD,
C:/Users/USER1/AppData/Local/Programs/Python/Python38-32/python.exe
F:/mysite/manage.py runserver
Hope this works :)
if you are using Redis Server on Windows, check it out if Redis Server is running, I had same problem and realized my Redis Server was not running, I ran it and now my manage.py commands work fine.
The same happened with me also, but this issue is a minor one as it happens if you have multiple versions of Python on your system, you can select a specific Python version by running python3 or whichever version you want.
SO you should start from the beginning, uninstall Django first then,
create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path:
for e.g:
python3 -m venv tutorial-env
//This will create the tutorial-env directory if it doesn’t exist, and also create directories inside it
Once you’ve created a virtual environment, you may activate it.
On Windows, run:
tutorial-env\Scripts\activate.bat
On Unix or MacOS, run:
source tutorial-env/bin/activate
Now,
In the command prompt, ensure your virtual environment is active, and execute the following command:
...> py -m pip install Django
NOTE:
If django-admin only displays the help text no matter what arguments it is given, there is probably a problem with the file association in Windows. Check if there is more than one environment variable set for running Python scripts in PATH. This usually occurs when there is more than one Python version installed.
Another solution, if you can, is to upgrade Django
pip install django --upgrade
Oftentimes one will get other unrelated issues to solve that are linked with the upgrade but once all is fixed the server should run just fine.
If you can't upgrade Django, this problem also happens when the code was built using Python 2.x and you're locally using Python 3.x.
The quicker fix in that case is to uninstall Python 3.x from your machine and make sure Python 2.x was added to the path. I've seen some developers setting up alias in PowerShell to have more than one version in the environment too.
I think the problem is in manage.py file (50%), check it with an another file that is correct.

django-admin.py is not working

Am new to django and i have been trying to set up a project with no success. When i type
django-admin.py startproject mysite i get this.
C:\Users\WASSWA SAM\Documents\django\djcode>django-admin.py startproject mysite
Usage: django-admin.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=all output
etc....
I have added it to my path like so
C:\Python26\Lib\site-packages\django\bin
And when i import django from interactive mode it works perfectly. What could be the problem. I am using Windows 7 and django 1.3.1. I installed it using setup.py.
I had the same problem; I found a working solution at https://groups.google.com/forum/#!msg/django-users/b76qSG3mV6g/jP1o0ny3i2kJ:
python C:\Python27\Scripts\django-admin.py startproject mysite
This is an error with Python's installation on Windows. If you have the regkey entry
HKEY_CLASSES_ROOT\py_auto_file\shell\command\open\
change the value from
"C:\Python27\python.exe" "%1"
to
"C:\Python27\python.exe" "%1" %*
(Or your equivalent installation location)
This ensures that command-line arguments are passed onto python, rather than explicitly ignored. This is fixed in the latest install of Python 2.7. %* is argv[]. "%1" is the script's absolute path.
I had the same problem and could not solve it for hours. Create a new project from Pycharm or any other program you are using, install Django and then instead of running
django-admin.py startproject *project_name* .
run
django-admin startproject *project_name* .
Ommiting .py extension worked for me and everything is running as expected now.
I don't think you need to have django\bin in the path.
I think what you need to add to your PATH though is C:\Python26\scripts and then you should be able to run the startproject script.
In my case, I use eclipse and you can start an eclipse project from within the eclipse environment using PyDev.
Go up to File > New > Other > (within the PyDev Folder) > PyDev Django Project. In the wizard it will allow you to setup most of the commonly used features of Django.

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