Reputation: 1213
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
Upvotes: 1
Views: 2473
Reputation: 4248
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.
Upvotes: 3