Skip to content
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

Best way to add sys dependencies of Python libraries? #1228

Open
YPares opened this issue May 24, 2024 · 5 comments
Open

Best way to add sys dependencies of Python libraries? #1228

YPares opened this issue May 24, 2024 · 5 comments
Labels
question Further information is requested

Comments

@YPares
Copy link

YPares commented May 24, 2024

I'm making a devenv setup to provide python and spaCy (which depends on zlib and libstdc++). I ended up with:

# devenv.nix
{ pkgs, ... }:
{
  packages = [ pkgs.zlib pkgs.stdenv ];

  languages.python.enable = true;
  languages.python.version = "3.11";
  languages.python.venv.enable = true;
  languages.python.venv.requirements = ./requirements.txt;

  enterShell = "export LD_LIBRARY_PATH=${pkgs.zlib}/lib:${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH";
}
# requirements.txt
spacy==3.7

Is that the recommended way to do so? (Ideally I'd like nix itself to provide spaCy, so it and its dependencies are locked along with the rest of the config, but adding it to packages resulted in build errors)

@YPares YPares added the question Further information is requested label May 24, 2024
@YPares
Copy link
Author

YPares commented May 24, 2024

Aha, I found https://github.com/cachix/devenv/blob/python-rewrite/tests/python-native-libs/devenv.nix Ok, nevermind. Though could the docs be updated to specify that case? A lot of python libs need that kind of setup, if that's the recommended way to go it should probably be made explicit.

@sandydoo
Copy link
Member

sandydoo commented May 26, 2024

@YPares, are you on the python-rewrite branch of devenv? If you upgrade to main, then you won't have to do the LD_LIBRARY_PATH shenanigans. See https://github.com/cachix/devenv/blob/main/tests/python-native-libs/devenv.nix.

@YPares
Copy link
Author

YPares commented May 28, 2024

@sandydoo I'm using devenv 1.0.5 (installed from nixpkgs-unstable).

EDIT: I reinstalled it directly from this repo's flake (nix profile install github:cachix/devenv/main#devenv) so I'm on the main branch, and the same problems remain.

@sandydoo
Copy link
Member

sandydoo commented May 28, 2024

@YPares, have you run devenv update as well?

Could you please post the error you're getting and instructions how to repro it?

I did the following and it seems to work (I'm not familiar with spacy though):

devenv.nix

{ pkgs, ... }:
{
  packages = [ pkgs.zlib pkgs.stdenv ];

  languages.python.enable = true;
  languages.python.version = "3.11";
  languages.python.venv.enable = true;
  languages.python.venv.requirements = ./requirements.txt;
}
python -m spacy download en_core_web_sm
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a sentence.")
print([(w.text, w.pos_) for w in doc])
[('This', 'PRON'), ('is', 'AUX'), ('a', 'DET'), ('sentence', 'NOUN'), ('.', 'PUNCT')]

@YPares
Copy link
Author

YPares commented May 29, 2024

@sandydoo Ok, I think I get the problem. I was using:

inputs:
  nixpkgs:
    url: github:NixOS/nixpkgs/nixpkgs-unstable

as my nixpkgs flake source. With it the env.LD_LIBRARY_PATH is still needed. But when using cachix/devenv-nixpkgs/rolling instead, then it's no longer necessary, and your setup above works.

The exact error was:

>>> import spacy
Traceback (most recent call last):
  File "/home/yves/dev/devenv-spacy-test/.devenv/state/venv/lib/python3.11/site-packages/numpy/core/__init__.py", line 24, in <module>
    from . import multiarray
  File "/home/yves/dev/devenv-spacy-test/.devenv/state/venv/lib/python3.11/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/home/yves/dev/devenv-spacy-test/.devenv/state/venv/lib/python3.11/site-packages/numpy/core/overrides.py", line 8, in <module>
    from numpy.core._multiarray_umath import (
ImportError: libz.so.1: cannot open shared object file: No such file or directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants