简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM