I’m following William Vincent @wsvincent book “Django for Beginners”.
I installed Python (in Windows) in the default global folder, downloading it from Python.org. C:\Users\UserName\AppData\Local\Programs\Python\Python38-32
After installing pipenv I installed django in the virtual envirornment: pipenv install django==3.0
Time has passed and I would like to update Python to version 3.9.1.
I did the same: I downloaded the version from Python.org, in the same folder C:\Users\UserName\AppData\Local\Programs\Python\Python39
I’m using Windows 10 and working with Visual Studio Code v 1.52.1. At first I tried with the command pallete in VS code (Ctrl+Shift+P
) → Python Select Interpreter and manually changed to Python 3.9.1.
Then I ran my django project and it seems to work, but I have an error in every import, like this one:
When I change the python version to the original one, the error ends.
What’s going on?
So, how to update the Python version in a Django project with pipenv?
Or is it better to install a specific Python version for each project? So we don’t use the global installation? How do you do it?
Thanks!!
Hi!
I’m not entirely sure but I think the interpreter you selected is your new Python installation (3.9.1) where Django doesn’t exist.
You could delete the old virtual env and recreate it with pipenv install django
. It should create a new virtual env with the newest python version.
After that, Ctrl+Shift+P
should show something like this

where you need to select the virtual env created, so VSCode can search for Django modules.
1 Like
Hi Marco!
You’re correct: Django isn’t installed in the global Python installation. But what I don’t get is why the project still runs 
I will try your suggestion about deleting and creating a new environment (but later, can´t now).
I was wondering if there is a way to do this without doing that.
Thank you very much.
I’ll keep you updated.
This YouTube tutorial from Corey Schafer suggests somthing similar to your solution.
It starts here 20:07
That’s why I said I wasn’t entirely sure. 
One thing that occurs to me is:
- You ran your project with the old virtual environment activated (Python 3.8), so everything is run normally.
- You changed the interpreter to Python 3.9.1 (VSCode uses this to autocompletion, syntax highlighting, etc.), so that explains the warnings.
1 Like
The virtual environment creates a localized copy of your python version to avoid conflicts with your global environment. Since you want to change which version of python the virtual environment uses, you’ll need to recreate the virtual environment with the new version of python.
1 Like
Thanks Tim, it seem that’s the solution.
Hi guys!
Thank you very much for your help.
This is what I did based on the YouTube tutorial I posted above (link). And also the Pipenv documentation.
There are actually two ways to solve this:
- Update Pipfile.
- You determine the python version you need in Pipfile, in this case I specify version 3.9 (which is already installed in the global directory)
[requires]
python_version = "3.9"
pipenv --python 3.9
You’re telling pipenv that the environment should be recreated with this Python version.
- Remove the virtual environment and re install everything.
- You first update Pipfile as in the first case.
- Then you remove the virutal environment
pipenv -rm
- And finally you re install:
pipenv install
It will install the Python version selected in Pipfile and the other dependencies.
I had a typo, here goes the second way again.
- Remove the virtual environment and re install everything.
- You first update Pipfile as in the first case.
- Then you remove the virutal environment
pipenv --rm
- And finally you re install:
pipenv install
It will install the Python version selected in Pipfile and the other dependencies.