How do I use pip, pipx and virtualenv of the current python version after upgrading?

1k views Asked by At

This is the first time I am upgrading python (from 3.11.3 to 3.12.0) and some questions came up along the way. I think I have somehow understood how Path works on windows, but am not getting the complete picture right now. At the moment I have the issue, that python and pip still by default use the old python installation, so this led to a few questions:

How do I use the correct version of pip?

My understanding is, that the version of pip which is Called is determined by which Path entry of Python\Scripts is preferred by Windows.

At the moment, python 3.11 and 3.9 are installed into C:\Program Files\, and their installation path is added to system PATH.

3.12 however is installed to C:\Users\...\AppData\Local\Programs\Python\Python312\ and the installation path is added to user PATH.

Should I just delete the PATH entries directing to python 3.9 and 3.11? Does Windows prefer system path over user path?

How do I ensure the right version of virtualenv and pipx are used?

In the Scripts directory, I can't find entries for pipx and virtualenv, and there are no seperate entries for pipx and virtualenv in either PATH. How does my Terminal know, where to find the correct executables? Is this managed by pip? And how do I get my system to use the newly installed versions of virtualenv and pipx which use python3.12?

Is there an easier way of upgrading my pipx installed tools than reinstalling all of them for a new python version?

I have some tools installed via pipx, e.g. hatch, mypy, ipython, virtualenv. Do I need to reinstall all of those tools for every python upgrade I make? Or is there a way to tell pipx that I want it to use a new python version now?

Edit: My Path entries

System Path:

C:\Program Files\Python311\Scripts\
C:\Program Files\Python311\
C:\Program Files\Python39\Scripts\
C:\Program Files\Python39\ 

User Path:

C:\Users\UserName\AppData\Local\Programs\Python\Python312\Scripts\
C:\Users\UserName\AppData\Local\Programs\Python\Python312\
C:\Users\UserName\AppData\Local\Programs\Python\Launcher\
C:\users\UserName\appdata\roaming\python\python311\scripts
1

There are 1 answers

0
Jan On BEST ANSWER

Through a lot of trial and error I figured it out, maybe it helps some people:

How do I use the correct version of pip?

In my case, I needed to remove python 3.9 and 3.11 (especially the Scripts folder, that is where pip.exe is located) from the system path. I also removed 3.11/Scripts from user path.

For my terminal to notice the 3.12 path, I had to relog after installing python 3.12.This seems to be the case with all entries in user path.

How do I ensure, that the right version of pipx and virtualenv are used?

If installed through pip, pipx and virtualenv are specific to the python version they were installed with. So I need to reinstall pipx and virtualenv using the correct version of pip.

Is there an easier way of upgrading my pipx installed tools than reinstalling all of them for a new python version?

Yes there is. When installing pipx with pip from python3.12, it automatically recognises it's installations from the version installed with 3.11. So when upgrading the python version, all one has to do, is reinstalling pipx.

If you want to upgrade the pipx packages to python3.12 aswell, you can use pipx reinstall-all.