I have an existing django project. Python version 3.11.9. I need to upgrade python to 3.12.4. I have tried using pipenv but fails. Information is sparse on upgrading python version in django.
FYI - I’m using vscode on windows 11.
You need to install Python 3.12 outside your virtual environment, then create a new virtual environment for Python 3.12 and install the necessary packages in it.* (Yes, you can have multiple different version of Python installed in your Windows system.)
(You don’t run Python in an virtual environment. You’re creating a virtual environment using Python to run Django.)
*Note: There are other ways of doing this, but this is typically the easiest and most straight-forward.
Hi Ken,
Yes of course I updated the global version of python to 3.12.4. I also open VScode (windows 11) and it shows it there as well as the global version. So all good there.
Note I watched Corey Schafer’s video on Pipenv, but his focus is on python .venv / new installs and not the Django environment. I tried to extrapolate from his video how to do this but there is info missing.
i.e.:
do u deactivate the venv before upgrading?
pipfile.lock issues
when I run
pipenv --python 3.12
GET THIS WARNING
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Seems to not do anything. So I tried deactivating my current venv. Then I ran it again
pipenv --python 3.12
Creating a virtualenv for this project…
Pipfile: C:\Users\EAI24909\OneDrive - Epson America\Desktop\Python Projects\epson.epsonVE\enoc_proj\Pipfile
Using C:/Users/EAI24909/AppData/Local/Programs/Python/Python312/python.exe (3.12.4) to create virtualenv…
[=== ] Creating virtual environment…created virtual environment CPython3.12.4.final.0-64 in 7300ms
- creator CPython3Windows(dest=C:\Users\EAI24909.virtualenvs\enoc_proj-EoZa463b, clear=False, no_vcs_ignore=False, global=False)*
- seeder FromAppData(download=False, pip=bundle, via=copy, app_data_dir=C:\Users\EAI24909\AppData\Local\pypa\virtualenv)*
- added seed packages: pip==24.1*
- activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator*
Successfully created virtual environment!
Virtualenv location: C:\Users\EAI24909.virtualenvs\enoc_proj-EoZa463b
I then Ctrl_Shift+P and notice the new venv / interpreter (See image)
I select this new venv 3.12.4
I then notice there are no packages installed…not even Django.
I look inside the pipfile and no packages.
So I ran this:
pipenv install requirements.txt -as it says in the pipenv documentation to do.
I start getting “pipfile lock” cannot lock and many many lines of errors. It finished and there are no changes to the pipfile and there is no pipfile.lock file as well.
BTW - this trashes my entire env. I do a python manage.py check and many errors.
Do I need to remove the new venv 3.12.4 env interpreter before trying again? If so how. What I find on the internet does not work…at all. Just trashed more things. Sorry frustrated here. As I see a lot of people are.
I cannot find anywhere (not even Django’s website or forum) step by step to patch python in a venv inside Django. Am I missing something here? This I would think is a common thing and there should be a section on Django’s website with this information.
Wow, i cannot believe that no one on Django forum knows how to actually update python version using pipenv in an active project? Or can point me to Django documentation on how to do this. Reading external sites and forums this process appears to be fraught with issues.
first install new version of python
remove older env from your project
have requirements.txt file
create new env
install requirements.txt file
Thank you for your reply. That does not work. I tried that. I had tried that more than once before i posted here. This causes pipfile creation errors. Other attempts errors on mysqlclient package. Each attempt it can’t get past making the pipfile. I appreaciate your help. Thank you.
can you give me link to your github project?
Please be aware, this is not a Django issue. This has nothing to do with Django itself, nor any Django related library. This is a general pipenv issue, one that you would encounter if Django was not involved at all.
(I don’t do Python development in Windows, and I have no direct experience with pipenv, but I did follow your steps far enough to see the errors you are reporting relative to the pipfile.lock file.)
You may be more likely to find your answers through other, pipenv-related support channels.