DEV Community

Cover image for How to upgrade the Python version in a virtual environment
Maria Campbell
Maria Campbell

Posted on

1

How to upgrade the Python version in a virtual environment

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
Enter fullscreen mode Exit fullscreen mode

Saving my current dependencies

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

pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

De-activating the virtual environment

Next, I had to deactivate the virtual environment:

deactivate
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Re-activating the virtual environment

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

source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

Installing saved dependencies

Next, I had to install my saved dependencies:

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

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.

Related Resources

Related Posts

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay