How to upgrade the Python version in a virtual environment

Saturday, January 11, 2025 at 1:59 PM | 2 min read

Last modified on Thursday, May 28, 2026 at 2:12 AM

#fullstack development, #macOS, #django, #pip, #python3, #dependencies, #django commons, #django debug toolbar, #third party packages, #venv, #virtual environment

Various tools on a wall

Photo by Mitchell Luo on unsplash.com

Table of Contents

I was working on a new project today (the official Django Polls app tutorial as a matter of fact), and I noticed that my virtual environment was using Python 3.12. But in my project, I am using Python 3.13.0. Using different versions of Python in the virtual environment vs in the code can create problems and conflicts. I had to upgrade my version of Python in my venv folder pronto!

Activating the virtual environment

First, I had to make sure that my virtual environment was activated in my project:

source venv/bin/activate

Saving my current dependencies

Next, I had to make sure to save my application's current dependencies:

pip freeze > requirements.txt

De-activating the virtual environment

Next, I had to deactivate the virtual environment:

deactivate

Deleting the current venv folder

Next, I had to delete the current venv folder. That is what I call my virtual environment folder. You might call it something else!

Creating a new venv folder

Next, I had to create a new venv folder using 3.13 since that is what I wanted to upgrade to:

python3.13 -m venv venv

Re-activating the virtual environment

Next, I had to re-activate the virtual environment:

source venv/bin/activate

Installing saved dependencies

Next, I had to install my saved dependencies:

pip install -r requirements.txt

And that's it!

Conclusion

In this post, I showed how to upgrade the Python version being used in a Django application's virtual environment.