@@ -203,28 +203,67 @@ There are also alternative solutions possible using tools like
203203python version switching to be less coupled from project management.
204204
205205
206- ## Does this work with 'uv', 'hatch', 'poetry', 'pipx ', and 'pixi '?
206+ ## Does this work with 'uv', 'hatch', 'poetry', 'pyenv ', pixi', and 'pipx '?
207207
208208Many tools will "just work" as long as they select the python found from the current
209209` PATH ` . Some tools can be helped along to do this more consistently.
210210
211- - ` uv ` will by default attempt to use the python shim found from ` PATH ` .
212-
213- - Set ` HATCH_PYTHON=python ` in your environment to tell ` hatch ` to default to
214- using the python shim found from ` PATH ` .
215-
216- - Set ` poetry config virtualenvs.prefer-active-python true --global ` to
217- configure poetry to default to using the python shim found from ` PATH ` .
218-
219- - Add something like ` export PIPX_DEFAULT_PYTHON="$(command -v python) ` to your
220- shell startup file to tell ` pipx ` to default to using the python shim found
221- from ` PATH ` . Although, if you're using ` uv ` already, you might as well be
222- using ` uv tool install ` instead of ` pipx ` .
223-
224- - At this time, I know of no way to configure ` pixi ` to use a uv-managed python
211+ - ** uv:** In most cases, ` uv ` will by default either attempt to use the python
212+ shim found from ` PATH ` or follow the same python discovery heuristic that the
213+ shim uses.
214+
215+ - ** hatch:** Set ` HATCH_PYTHON=python ` in your environment to tell hatch to
216+ default to using the python shim found from ` PATH ` .
217+
218+ - ** poetry:** Set ` poetry config virtualenvs.prefer-active-python true --global `
219+ to configure poetry to default to using the python shim found from ` PATH ` .
220+
221+ - ** pyenv:** The ` uv-python-shims ` solution is meant to be a ** replacement**
222+ for ` pyenv ` shims. However, ` uv ` installs pre-built pythons while ` pyenv `
223+ builds pythons from source. Pre-built python installation is much faster than
224+ building from source so they are preferred in most usecases. But if you still
225+ wish to build from source, you can continue using ` pyenv ` for this purpose.
226+ Just ensure that the ` uv-python-shims ` directory is found in the PATH ** before**
227+ the ` pyenv ` shims directory. The ` uv python find ` will then be able to discover
228+ the pyenv-managed pythons as long as a suitable uv-managed python matching the
229+ version constraints is not found first.
230+
231+ - ** pixi:** At this time, I know of no way to configure ` pixi ` to use a uv-managed python
225232 or to default to using the python shim found from ` PATH ` . The ` pixi ` tool
226- manages pythons entirely within the pixi-managed virtual environment for
227- a ` pixi ` project similar to how ` conda ` works.
233+ manages pythons entirely within the pixi-managed virtual environment similar
234+ to how ` conda ` works.
235+
236+ - ** pipx:** By default, the python selection when using ` pipx ` is deterministic
237+ and is not affected by the presence of ` .python-version ` files or virtual
238+ environments. This makes sense since having all your pipx-installed tools use
239+ different pythons can be surprising and difficult to manage. If despite this,
240+ you still want to use the dynamic python discovery made possible with these
241+ uv-python-shims, you can add something like the following to your shell
242+ startup file.
243+ ```
244+ export PIPX_DEFAULT_PYTHON="$(command -v python)
245+ ```
246+
247+ - ** uv tool:** UV's equivalent to ` pipx install ` is ` uv tool install ` .
248+ Both install globally-accessible python-based tools in isolated virtual
249+ environments but there is a subtle difference between how the two select
250+ the python version installed in that environment. The ` uv tool ` mechanism
251+ appears to follow the same discovery heuristic as the rest of ` uv ` although
252+ it ignores version constraints defined in "local" configuration
253+ (local ` .python-version ` files or project/workspace ` pyproject.toml ` files).
254+ However the presence of an activated virtual environment or the existence
255+ of a non-activated virtual environment found in the current directory or
256+ parents may result in the selection of the python from that environment.
257+ This feels like a possible footgun if you expect the more deterministic
258+ behavior followed by ` pipx ` . To get the more deterministic pipx-like behavior,
259+ you can set ` UV_PYTHON ` environment variable to point to the desired default
260+ python path. UV_PYTHON can be either a version constraint or a path to a python
261+ executable. However this will set the default python for all ` uv ` operations
262+ which is likely undesirable. An alternative is just to define a special
263+ alias/function within your shell startup file just for ` uv tool install ` :
264+ ```
265+ uv-tool-install() { UV_PYTHON=[...] uv tool install "$@" }
266+ ```
228267
229268
230269## Notes and caveats
0 commit comments