-
Notifications
You must be signed in to change notification settings - Fork 296
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
Python + Poetry + Numpy ImportError with multiple python versions #1264
Comments
Not sure about your lock file, and which version of NumPy you're using, but I noticed that a "vanilla" flake (similar to https://devenv.sh/guides/using-with-flakes/, with the obvious configs for Python, as in your example) is succeeding to run NumPy 1.x.y, but failing with NumPy 2.0.0. It is also failing with other compiled packages (e.g. Pandas or QuTiP). I'm now testing https://github.com/cachix/devenv-nixpkgs |
@ianepreston I believe the main discussion to be still related to #773, so the problem should be solved there (I believe @Atry was mainly facing it). However, a highly discouraged workaround that you can find on the NixOS Discourse is to This is partially what Devenv itself is doing devenv/src/modules/languages/python.nix Lines 13 to 27 in f810f8d
and it should be the purpose of the libraries option. But in this case, it would be restricted to the Python executable,https://github.com/NixOS/nixpkgs/blob/89c49874fb15f4124bf71ca5f42a04f2ee5825fd/pkgs/development/interpreters/python/wrapper.nix#L45 https://nixos.org/manual/nixpkgs/stable/#fun-makeWrapper while setting manually is exposed to all executables in your shell (which is quite more aggressive). Not sure why the I'm pretty sure it's an ugly solution, with many drawbacks, but it may solve your issues while waiting for a proper one. (in case you want to know which is the exact path to the library you want to use, assuming it's already available in your |
Same thing here, either
If I don't enable python with devenv's
i'm going to give up on python via nix 😞 pd: this is on linux - on macos it seems to work 🤷♂️ edit: {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
systems.url = "github:nix-systems/default";
devenv.url = "github:cachix/devenv";
};
outputs = {self, nixpkgs, devenv, systems, ...} @ inputs:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
packages = forEachSystem (system: {
devenv-up = self.devShells.${system}.default.config.procfileScript;
});
devShells = forEachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in {
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({pkgs, config, ...}: {
# https://devenv.sh/reference/options/
env = {
VIRTUAL_ENV = config.env.DEVENV_ROOT + "/.venv";
PYTHONPATH = config.env.DEVENV_ROOT;
MYPYPATH = config.env.DEVENV_ROOT;
# so C extensions can find dyamically linked libraries
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc pkgs.zlib];
};
packages = [
pkgs.python312Packages.python
];
...
})
];
};
}
);
};
} |
I didn't end up ditching nix but I did go over to poetry2nix and am actually pretty happy with my setup now: https://blog.ianpreston.ca/posts/2024-06-30-nix.html#back-to-poetry-with-poetry2nix |
I'm facing the same issue with the numpy (and any package that depends on it) which unfortunately makes devenv not really usable for Python work as of right now. |
I'm hitting this as well. The issue is that Poetry is using an unwrapped interpreter, thus In creating a minimal reproducible example, having |
This feels very similar to #1095 but I think it's different enough to warrant a new issue, although if you'd prefer me to close this and carry on that thread I'm happy to do so.
I've been trying to build out a devenv with python and poetry that can support libraries like numpy. As with the poster in #1095 I was initially getting the
Original error was: libz.so.1: cannot open shared object file: No such file or directory
error.Updating my
flake.nix
to includelibraries = with pkgs; [zlib];
in the python section, blowing away.venv
,.direnv
,flake.lock
, andpoetry.lock
seemed to resolve the issue, I was able to launch python and import numpy. However, I got greedy. I want to be able to develop against multiple versions of python so I have multiple dev shells defined for each python version I want to support in the library I'm developing. Activating one of those environments caused the original import error to return. Switching back to the previously working environment also produces the error now, and deleting all the above mentioned files and restarting no longer resolves the issue for any environments. I'm really at a loss on this one. I get it not working, I get it working, but I don't get it working then not working. I assume there's some hidden file or setting I'm not touching but I don't know what it could be.My
flake.nix
looks like this:pyproject.toml
is very simple, I have a couple of basic dependencies that will work to ensure my environment is being activated and then a requirement for pandas:Any advice for additional troubleshooting I can try would be appreciated.
The text was updated successfully, but these errors were encountered: