conner.xyz
conner.xyz

Reputation: 7285

How does pipx know which Python version to use?

I'm a strong pyenv and poetry user that's beginning to use pipx and looking to learn more about how it works. Specifically, I'd like to understand how it determines which Python version to use when installing.

I've noticed that it seems to search PATH for existing references to applications when you pipx install <package> to make existing installations accessible globally. This, for instance, works well with pyenv where it pipx will find a version of the package you install across any Python versions installed via pyenv.

pipx install cookiecutter
⚠️  Note: cookiecutter was already on your PATH at ~/.pyenv/shims/cookiecutter
  installed package cookiecutter 1.7.3, Python 3.9.6
  These apps are now globally available
    - cookiecutter
done! ✨ 🌟 ✨

But what if it's a package you've never installed before? And there's a package version compatible with 3.6, 3.7, 3.8 – how will it determine with Python version to use when installing this package?

Upvotes: 35

Views: 29913

Answers (2)

sanbor
sanbor

Reputation: 1282

Check where your pipx is installed by running which pipx. Uninstall it or remove it (e.g. rm $HOME/.local/bin/pipx).

Then install it with python -m pip install pipx.

Now your pipx installation is linked to the python version you are using.

You will have to install pipx for every of your python environments (i.e. if you are using [email protected] and switch to [email protected] you will have to install install it again)

Upvotes: 1

conner.xyz
conner.xyz

Reputation: 7285

I've found you can provide the Python version PipX should install the package into by providing it as an argument to the install command (see below).

More specifically, when using pyenv, you can switch to the version you desire to install into and then provide $(which python) to automatically provide the path to that python version...

pyenv shell 3.X.X
pipx install <package-name> --python $(which python)

Upvotes: 55

Related Questions