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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay