uv
uv copied to clipboard
`uv pip compile --python-version ...` breaks when pyenv is used
$ uv pip compile --python-version 3.9 requirements.in -o requirements.txt
error: Querying Python at `/home/adrian/.pyenv/shims/python3.9` failed with status exit status: 127:
--- stdout:
--- stderr:
pyenv: python3.9: command not found
The `python3.9' command exists in these Python versions:
[...]
Note: See 'pyenv help global' for tips on allowing both
python2 and python3 to be found.
---
Thank you! This is a problem with the shim unfortunately. We can fix this but it probably won't be today.
@ThiefMaster I hit this as well and realized that this could be fixed by adjusting my pyenv configuration!
With pyenv you are able to activate multiple versions at the same time. See below for text in the pyenv README
NOTE: You can activate multiple versions at the same time, including multiple versions of Python2 or Python3 simultaneously. This allows for parallel usage of Python2 and Python3, and is required with tools like tox. For example, to instruct Pyenv to first use your system Python and Python3 (which are e.g. 2.7.9 and 3.4.2) but also have Python 3.3.6, 3.2.1, and 2.5.2 available, you first pyenv install the missing versions, then set pyenv global system 3.3.6 3.2.1 2.5.2. Then you'll be able to invoke any of those versions with an appropriate pythonX or pythonX.Y name.
Based on the above, I ran the following so that all my pyenv versions are available in global.
pyenv versions --bare --skip-aliases --skip-envs | xargs pyenv global
This ensured that all the versions are available for use in my shell:
❯ pyenv versions
system
* 3.8.18 (set by /Users/brian/.local/share/pyenv/version)
* 3.11.6 (set by /Users/brian/.local/share/pyenv/version)
❯ python3.8 --version
Python 3.8.18
❯ python3.11 --version
Python 3.11.6
And lastly I confirmed that this was successfully usable by uv venv (I also tested with uv pip compile -p):
❯ uv venv -p 3.8
Using Python 3.8.18 interpreter at /Users/brian/.local/share/pyenv/versions/3.8.18/bin/python3.8
Creating virtualenv at: .venv
❯ uv venv -p 3.11
Using Python 3.11.6 interpreter at /Users/brian/.local/share/pyenv/versions/3.11.6/bin/python3.11
Creating virtualenv at: .venv