Home > database >  Django runserver not working; error: Python was not found. Did I miss something?
Django runserver not working; error: Python was not found. Did I miss something?

Time:02-05

It's been a while since I posted anything here, and now my problems have become more advanced. For reference, I'm running on Win10.

I'm trying to use the Django framework. Python's been installed on my computer forever; it's the latest version, and it's installed on environment variables/added to system paths. I think those are enabled by default, but I did make sure that they were checked when I reinstalled it.

pip's been updated too. Django installed successfully. I managed to get all the way to installing my new project with django-admin startproject PROJECTNAME, but when I try to run python3 manage.py runserver, I'm getting this error:

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

This "Python was not found" error is the main problem that I'm trying to figure out. Nothing I do as a fix seems to get rid of it.

...Interesting. If I type in python --version, I get a response (Python 3.11.0). Here's what I get if I do pip freeze:

asgiref==3.6.0
Django==4.1.6
sqlparse==0.4.3
tzdata==2022.7

Python IDLE runs fine; all .py files run fine. Alright. So, with that in mind and in accordance to a lot of popular advice I've seen floating around, I added the Path to my Environment Variables. For space-saving reasons, my Python is installed on my D drive rather than C. I've made sure that there weren't any leftover Python files that conflicted.

I've uninstalled and reinstalled, double checked my installations, and Django is in D:\ProgramData\Python311\Scripts with pip and everything else I need. I did also disable the shortcut from Settings > Manage App Execution Aliases, but when I did that, I got this error:

python3 : The term 'python3' 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.

Based on some other things I've seen, I've also tried:

python manage.py runserver
python3 ./manage.py runserver

I ended up having to enable the options again just to use Python correctly. And I have been closing and reopening the command line whenever I make changes. Though it updates automatically to fit what I've been doing, I wanted to make sure I didn't overlook any possibility.

I even uninstalled Django for a third time, installed the virtual environment (which I realised I skipped), and did it all again. And then, after a long series of figuring out how to activate the virtual environment and enabling scripts to run, I'm finally in (venv) D:\PROJECTNAME, and I tried... to run it again.

I'm still getting the Python not found error. orz

I've been at it for two hours or so, and I feel like I'm running into a dead end. I think I've finally met my match here.

This is my first time using frameworks like this, and it's been a while since I've installed anything through command line on Windows. I'm not very great at this, so I know that I'm making some amateurish mistakes somewhere. Please let me know if I'm doing anything wrong or missed something obvious.

Please.... I just want to use Django....

Thanks in advance!

CodePudding user response:

This question really is not proper for a PowerShell Q&A, but let see if the below helps.

If you are trying to run django from PS, then:

pip install django
django-admin startproject YourProjectNamehere

lastly, hit your dev server

HTTP://YourDevServerName:YourDevServerPortNumber

Also, be sure that you've activated your virtual environment, never assume it is until you test it. Of course, be sure to change directly to the root of your project.

Again, if you are using python, directly, then, it's more prudent to stay in your pristine python shell vs executing from a PowerShell consoler/terminal, thus eliminating any PowerShell particulars.

CodePudding user response:

first download manually python on your computer , therefore install django from official website , www.python.org/downloads/, https://www.djangoproject.com/download/,

if you're on linux, pip install Django==4.1.6

after installing that use ,

django-admin

  • Related