Upgrading Python in an Existing pipenv Virtual Environment

While I have a love-hate relationship with pipenv–make no mistake, it’s definitely more love than hate–the things that I hate seem to be more due to a lack of (quality) documentation than a lack of anything else.

A simple example is upgrading the version of python running in an existing virtual environment. My “google-fu” was returning results that seemed to contradict each other, offer vague advice, or be old enough to make me question the validity of the answer.

So I had no choice but to try some of them out. But at least I tried it on a project that I was just doing a test drive on–so no real loss if things were to go wrong… First though, I had to pick from a small number of different commands, and I decided to go with the one that was mentioned the most:

pipenv --python 3.8.10 install

(As I was running 3.8.6 & wanted to get the latest patches for 3.8.)

Other than being prompted if I wanted to download 3.8.10–and waiting for the download to complete–it was just like most other pipenv actions. And it did exactly what I was attempting to do. Success!

And now I just have to figure out how to resolve my biggest gripe: how to get my prompt & aliases working inside the virtual environment…

UPDATE: I highly recommend using pipenv --help and pipenv COMMAND --help (where COMMAND is check, clean, graph, install, etc.) as pipenv install --help doesn’t explicitly say “this is how you upgrade python in your virtual environment, but it is strongly implied. (Doing this sooner would have saved me some time.)

UPDATE 2: It seems that maybe some subtle changes have been made to pipenv. Running the pipenv --python... command above by itself doesn’t seem to work anymore. You need to remove the existing virtual environment & rebuild it. Therefore, you need to do the following two commands to bump up the python version:

pipenv --rm
pipenv --python X.Y.Z install

(Just don’t forget to replace X.Y.Z with the desired python version!)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.