On the command prompt, (Windows 10) I created a virtual environment, I then created a new project, I installed django in the virtual environment using pip. Then decided to run the command
python manage.py runserver
To run djangos web server,
This returned with
"...can't open file 'manage.py': [Errno 2] No such file or directory"
I did see a similar question to this on this platform but it seems to only apply to those using linux. Where answers specify to use the ls command, which is not applicable on Windows command prompt. I have tried this multiple times but i just can't open
manage.py
When running a command on the command prompt, it is necessary to provide the correct path to the file.
Let's pretend you have your django files stored in a folder with the following path:
C:\my_stuff\subfolder\django_project >
Presume that when you run the dir command (the Windows analog to the ls command you mention in your question) it might show something like this:
C:\my_stuff\subfolder\django_project > dir
blog
db.sqlite3
manage.py
mysite
If you were to then run your command:
C:\my_stuff\subfolder\django_project > python manage.py runserver
Everything should work fine. But if you are in a different directory, you will get the error you describe. For example, this will fail.
C:\my_stuff\subfolder > python manage.py runserver
If, for some reason, your Windows command prompt does not show you which directory you are in, you can run the cd command to confirm where you are.
An alternate method is to point the python interpreter to the location of the manage.py script, by providing the path:
C:\my_stuff\subfolder > python django_project\manage.py runserver
But this sometimes introduces subtle problems, because scripts like manage.py might be written with the expectation that they will be run from the directory they are stored in. Your mileage may vary.
Related
I tried to run command "python manage.py runserver" in VS code but i always get this message:
bash: /c/Users/ACER/AppData/Local/Microsoft/WindowsApps/python: Permission denied
Python permission denied picture
And also, i tried to run command "py manage.py runserver" still it does not run, instead it says:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
py manage.py runserver pic
VScode just runs on top of Windows Powershell, so it is not related to VScode, it is probably your python installation.
This is a quick tutorial on installing python, take a look on step 6 as is guides you to setup PATH variables. Also, using virtualenv would solve this issue and is a good practice.
I have to run the following set of commands after opening a windows cmd prompt
D:
cd Dev\project\backend
.\venv\Scripts\activate
python manage.py runserver
How to write a script(.bat) file for running these commands and the runserver will stay showing the output
I tried to put these commands in django.bat and double click, but a cmd window opens and within a fraction of second it closes. Dont know what happened
Instead of activating the venv then running manage.py separately, you should run directly using the python.exe from your virtual env.
It should look like this:
> D:\Dev\project\backend\venv\Scripts\python.exe D:\Dev\project\backend\manage.py runserver
I don't really know what you intent to use this for, but in windows you should run your Django project using IIS. Check out django-windowsauth, you can use it to run Django on IIS in few commands. https://github.com/danyi1212/django-windowsauth.
Just skip adding the middleware and the authentication backend of you don't need Windows Authentication on your site.
I tried to do this recently, but had to move onto something else quickly; given your question it's a nice opportunity to return to it, and I believe I've found the answer!
From what I found on my Laptop just now, the issue is with the activate line
.\venv\Scripts\activate
On Windows, this is another .bat file, and I suspect that calling it runs in a new cmd instance, rather than the current one
So I simply copied the entire contents of activate.bat and put it into my custom script, and it worked!
#echo off
cd D:\Dev\project\backend
-> Paste entire contents of activate.bat on this line <-
.\manage.py runserver
I've installed Superset following the installation guide in the apache superset web page, for Python 3.7.
Even though I can manually start the server, when I'm trying to script the startup steps and cron them, it fails.
The output of the execution is the following:
superset: command not found
I've read the replies of this topic but nothing applies to this case.
I'm not using virtualenv for the installation.
These are the output of the which commands:
ec2-user#Superset-STAGE /var/spool/mail$which python3
/usr/bin/python3
ec2-user#Superset-STAGE /var/spool/mail$which superset
~/.local/bin/superset
ec2-user#Superset-STAGE /var/spool/mail$sudo superset
sudo: superset: command not found
Would you please guide me on how to have my script working without failure? Script looks like below.
superset init
wait
superset runserver -d
Cron runs as root, which means its home directory is /root rather than /home/ec2-user as you expect. This means that it will not be able to find /home/ec2-user/.local/bin/superset because it neither looks for executables in a ~/.local/bin/superset nor is it logged in as a user that has such a directory. A quick fix here is to use the full path, but I would recommend moving the executable to a more appropriate directory such as /usr/local/bin and then adding it to the PATH variable in /etc/profile
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
I'm using Python 3.4.2 and Django 1.7.1
I've been able to create a folder called mysite with its content like shown in the tutorial.
But when I run the command manage.py runserver nothing happens:
C:\Users\thEpuQ8f\Dropbox\zephyrus>manage.py runserver
I get following message in the command line:
Usage: manage.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on exception
--no-color Don't colorize the command output.
--version show program's version number and exit
-h, --help show this help message and exit
Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
# and so forth
You probably don't have the correct PYTHONPATH.
You know what has worked for me really well on windows.
My Computer > Properties > Advanced System Settings > Environment
Variables >
Then under system variables I create a new Variable called PythonPath.
C:\Python34;C:\Python34\Lib;C:\Python34\DLLs;
Where Python34 is the folder of the Python. I don't know what's the correct folder name for python3. When you install the Python with installer, it should create PYTHONPATH automatically. So worst case scenario is that you just reinstall it.
Source: https://stackoverflow.com/a/4855685/73010
Try this command:
python manage.py runserver
Adding python in front of your command will run your python file.
If it produces errors, then make sure that python is installed and python install dir is listed in your PATH environment variable.
When it runs, try opening this URL in your web browser of choice to see if it works.
Then you should see a page like this: