Reputation: 21
I have two versions of Python installed (OS: Windows 10). The original version is 3.8.2. I installed 3.11.1 and did not have it added to PYTHONPATH. I created a virtual env using py -m venv .env
. Despite using py
, the virtual environment runs both Python 3.8.2 and 3.11.1 depending on whether I type python
or py
. Inside the virtual environment I installed a newer version of Django (4.1.5) using py -m pip install django
, which successfully installed Django within the Python311 folder on my system. However, no django-admin.py file was installed, just django-admin.exe. To ensure I created my project using the newer version of Django, I navigated to the folder where the django-admin.exe file exists and ran the following:
py django-admin.exe startproject <*project_name*> <*full_path_to_project_folder*>
The settings.py file shows it was created using Django 4.1.5, but whenever I start my project it runs using Django 3.0.4 (the pre-existing version). I am starting it using py manage.py runserver
, to ensure Python 3.11.1 is being used. I have tried it both inside and outside my virtual environment. I have added the python311\Scripts folder at the top of my Path environment variables, and have uninstalled and reinstalled Django 4.1.5.
At this point I am at a loss as to why I cannot get the newer version of Django to run. I have tried numerous Google and SO searches and have not found any similar issues or anything to point me in the right direction. I wondered whether it might have to do with django-admin.py not being installed with Django 4.1.5, so I looked for the django-admin.py file in the Django 4.1.5 source code with no success. I then saved the django-admin.py file from the 3.0.4 version into the python311/Scripts folder updated to reference the python311\python.exe, but the system still loads the one from the python38/Scripts folder. Hoping for some additional ideas to try.
EDIT: After adding 3.11.1 to Path and reinstalling Django I deleted and recreated the Django project. The system still wouldn't find the django-admin.py I added to the python311\Scripts folder, even using the full path, so I used the following command to create the project:
py \full\path\to\django-admin.exe startproject project_name .
Same issue: The project was created with Django 4.1.5, but runserver still uses 3.0.4.
Upvotes: 1
Views: 200
Reputation: 21
I was able to ultimately solve the problem by adding the \python311 folder to the Path (leaving off \Scripts). So I now have both \python311 and \python311\Scripts on the Path in addition to the original \python38 and \python38\Scripts locations. Runserver now runs with Django 4.1.5.
Upvotes: 1