Your Ad could be here. I want to connect my readers to relavant ads. If you have a product targeted at developers, let's talk. [email protected]

"cell shaded, long, full body, shot of a cybernetic blue soldier with glowing pink eyes, llustration, post grunge, cinebatic dramatic atmosphere, sharp focus, pink glowing volumetric lighting, concept art by josan gonzales and wlop, by james jean, Victo ngai, David Rubín, Mike Mignola, Laurie Greasley, highly detailed, sharp focus,alien,Trending on Artstation, HQ, deviantart, art by artgem" -s50 -W832 -H416 -C7.5 -Ak_lms -S70567464

I love using pipx for automatic virtual environment management of my globally installed python cli applications, but sometimes the application is not compatible with your globally installed pipx

Which version of python is pipx using??

This one took me a minute to figure out at first, please let me know if there is a better way. I am pretty certain that this is not the ideal way, but it works.

My first technique was to make a package that printed out sys.version.

# what version of python does the global pipx use?
pipx run --spec git+ pyvers

# what version of python does the local pipx use?
python -m pipx run --spec git+ pyvers

Let's setup some other versions of python with pyenv

If you don't already have pyenv installed, you can follow their install instructions to get it.

pyenv install 3.8.13
pyenv install 3.10.5

I usually require a virtual environment

I set the PIP_REQUIRE_VIRTUALENV environment variable to true to ensure that the virtual environment is activated when pip installing, this makes it so that I can't accidentally use the global env, which is typically not what I want to do.

# for windows users

This goes right into my shell startup script ~/.bashrc or ~/.zshrc.

Exceptions happen

This is my one exception. I've had better luck putting pipx right in the global python environment. Not the system python, but each python version that I install with pyenv.

# for windows users

Let's install pipx

First up is python 3.10.5

pyenv global 3.10.5
pip install pipx
pipx run --spec git+ pyvers

3.10.5 (main, Jun  6 2022, 18:49:26) [GCC 12.1.0]

Next is python 3.8.13j

pyenv global 3.8.13
pip install pipx
pipx run --spec git+ pyvers

3.8.13 (default, Aug  8 2022, 21:06:56)
[GCC 12.1.0]

Now once I close this shell I will always end up with PYTHON_REQUIRE_VIRTUALENV=true, since it's in my shell startup script. So make sure that you reset it or kill this shell before doing any damage.