-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: uv fails to detect nixpkgs provided python as a valid system-managed interpreter when it's installed with libraries #11529
Comments
If you share verbose ( |
(Thank you for the well-written issue!) |
$ uv venv --verbose
DEBUG uv 0.5.31
DEBUG Found project root: `/home/sol/oss/uv-test`
DEBUG No workspace root found, using project root
DEBUG Reading Python requests from version file at `/home/sol/oss/uv-test/.python-version`
DEBUG Using Python request `3.12` from version file at `.python-version`
DEBUG Searching for Python 3.12 in search path
DEBUG Found `cpython-3.12.8-linux-x86_64-gnu` at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3.12` (first executable in the search path)
DEBUG Ignoring Python interpreter at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3.12`: system interpreter required
DEBUG Found `cpython-3.12.8-linux-x86_64-gnu` at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3` (search path)
DEBUG Ignoring Python interpreter at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3.12`: system interpreter required
DEBUG Found `cpython-3.12.8-linux-x86_64-gnu` at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python` (search path)
DEBUG Ignoring Python interpreter at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3.12`: system interpreter required
× No interpreter found for Python 3.12 in search path
$ uv run --verbose hello.py
DEBUG uv 0.5.31
DEBUG Found project root: `/home/sol/oss/uv-test`
DEBUG No workspace root found, using project root
DEBUG Discovered project `uv-test` at: /home/sol/oss/uv-test
DEBUG Acquired lock for `/home/sol/oss/uv-test`
DEBUG Reading Python requests from version file at `/home/sol/oss/uv-test/.python-version`
DEBUG Using Python request `3.12` from version file at `.python-version`
DEBUG Checking for Python environment at `.venv`
DEBUG Searching for Python 3.12 in search path
DEBUG Found `cpython-3.12.8-linux-x86_64-gnu` at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3.12` (first executable in the search path)
DEBUG Ignoring Python interpreter at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3.12`: system interpreter required
DEBUG Found `cpython-3.12.8-linux-x86_64-gnu` at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3` (search path)
DEBUG Ignoring Python interpreter at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3.12`: system interpreter required
DEBUG Found `cpython-3.12.8-linux-x86_64-gnu` at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python` (search path)
DEBUG Ignoring Python interpreter at `/nix/store/y3lw7d6xw2s8nsjggbl8f0zwmd0wrgj2-python3-3.12.8-env/bin/python3.12`: system interpreter required
DEBUG Released lock at `/tmp/uv-9565ebfd5be59662.lock`
error: No interpreter found for Python 3.12 in search path Hope this helps! :) |
Looks like your theory was correct uv/crates/uv-python/src/discovery.rs Lines 666 to 680 in 81966c4
uv/crates/uv-python/src/discovery.rs Lines 709 to 715 in 81966c4
uv/crates/uv-python/src/interpreter.rs Lines 246 to 252 in ddbc6e3
Is there a way we can tell that these Nix environments are special? What does |
Hard to say. A perhaps decent heuristic would be to check the The maintainers for the nixpkgs distribution of python are better qualified to answer that question. Don't really know the best way to get in contact with them, perhaps could open an issue on nixpkg's github.
|
As a note, this is ~a duplicate of #4450 which may have some pertinent discussion |
Thanks for linking this! I wasn't aware of the |
For reference, if anyone bumps into this issue, here's a devshell that allows you to mix nix-managed and uv-managed libraries: {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
python = pkgs.python3;
pythonEnv = python.withPackages (p: [
# Here goes all the libraries that can't be managed by uv because of dynamic linking issues
# or that you just want to be managed by nix for one reason or another
p.pandas
]);
in
{
devShells.default =
with pkgs;
mkShell {
packages = [
uv
python
pythonEnv
];
shellHook = ''
export UV_PYTHON_PREFERENCE="only-system";
export UV_PYTHON=${python}
'';
};
}
);
} You can even do |
Summary
As of version
0.5.31
, the latest available onnixpkgs-unstable
, uv fails to recognize a nixpkgs installation of python as a valid system-managed interpreter when it's installed with libraries through thepython3.withPackages
function. This differs from version0.4.30
, the the latest on the24.11
channel, which does recognize it.I've made a small repo showcasing the issue: https://github.com/iniw/uv-test
When pointing the
nixpkgs
input tonixos-24.11
:When pointing it to
unstable
:This is a problem because compiled libraries, like
pandas
, must be installed directly by the nix environment since the pre-built binaries dynamically link to libc, making them unfit for NixOS. Read more about this here.I assume that the issue is that the python binary, when using libraries, is a virtual environment, which uv then detects and rejects on the basis that a "global" python interpreter shouldn't be a venv. This was probably done for valid reasons, but it's a shame that it severely limits uv's support for NixOS.
Platform
NixOS (Linux 6.6.76 x86_64 GNU/Linux)
Version
0.5.31/0.4.30
Python version
3.12.8
The text was updated successfully, but these errors were encountered: