-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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] ctypes.util.find_library should return full path to the library #7307
Comments
Can you provide exact steps to reproduce? |
# shell.nix
let pkgs = import <nixpkgs> {};
in with pkgs;
stdenv.mkDerivation rec {
name = "test";
src = ./.;
buildInputs = [
python2
libnfc
];
} # nfc.py
import ctypes
import ctypes.util
lib = ctypes.util.find_library('nfc')
print('Library: ' + lib)
ctypes.CDLL(lib) $ python2 nfc.py
Library: libnfc.so.5
Traceback (most recent call last):
File "nfc.py", line 7, in <module>
ctypes.CDLL(lib)
File "/nix/store/5aq9sjd0g4frmpqni0a6zykzkcnzc3al-python-2.7.9/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libnfc.so.5: cannot open shared object file: No such file or directory // nfc.c
#include <nfc/nfc.h>
int main()
{
nfc_context *c;
nfc_init(&c);
nfc_exit(c);
return 0;
} $ gcc -lnfc nfc.c
# OK |
I assumed this was expected to work, because I saw this patch. But now I looked around nixpkgs and seems that everyone else is patching I also reread the docs and noticed, it says that |
@kirelagin for now set |
It's a bit harder since |
As I said, Python docs state that on Linux |
It can't break things more than they currently are - as it doesn't even work due to prefix being unknown. |
Yeah I'm getting bitten by this one again. |
This is the line that gets executed on linux: https://github.com/python/cpython/blob/2.7/Lib/ctypes/util.py#L242 |
So if you were to execute
I think we should replace this with our own implementation |
I believe all the code using |
That's the thing, I don't want to maintain every package and patch it when it uses |
@domenkozar well, I don't think there's any good solution to that unfortunately. |
@domenkozar perhaps a special env variable |
We could use http://linux.die.net/man/8/ldconfig to generate the cache at build time. find_library then uses |
(triage) there have been a few patches, is this fixed now? |
We haven't solved it universally yet. |
Both are interesting options.
So, if we consider the ldconfig cache, then the cache has to be available during runtime, and the interpreter has to be able to find it. As soon as we put packages together in say an env we end up with multiple caches, so we would have to rebuild the cache as well. We should be able to patch the interpreter to load an environment variable that points to the cache. Then we can build the cache 1) whenever we build a Python package and 2) when we build an env. A downside is that when building a cache all So, we patch Python to check for
|
Are there any updates to this issue, please? |
Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly:
|
Trying to build another Python library and get the same error. Looks like it's still important. |
This is not actually an issue. |
Still unsure what's a valid workaround here. Setting |
I am also trying to fix the a find_library call in a python package, for libsnd. Like @michaelcadilhac , setting
Edit: I am using mach-nix, and the problem was that I had configured mach-nix (as default) to prioritize wheel and sdist packages. Instead, the nixpkgs version of pysoundfile already handles patching to find libsndfile. I just had to add this to my mach-nix.mkPython arguments: I am still running into the problem for other python packages using dlopen, though, specifically ones utilizing opencl. |
I marked this as stale due to inactivity. → More info |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/screenshot-with-mss-in-python-says-no-x11-library/14534/4 |
I marked this as stale due to inactivity. → More info |
Just for clarification, it seems possible to fix this issue by patching |
I'm still interested in this issue. It's just bitten me now and I worry I'm not experienced enough to solve this properly.
|
@reivilibre Have you tried the workaround (patching the call out)? |
I'm running into this issue with a Calibre plugin. Even if I add the required library to Calibre's deps, the plugin, which uses find_library, can't find it. Because the actual code is part of a plugin installed in the my home directory, not by nix, patching it to use an absolute path instead isn't really practical, and would break every time the path changed due to an update+garbage-collect. |
I've went really deep into this one after all this time, so I'll document my findings. I've pushed the changes into cachix/devenv#745, but the crucial bit is here: We wrap LD_LIBRARY_PATH around python interpreter and give it an explicit list of packages it will be able to link from. This relies on python/cpython@82df3b3, which is only present in Python 3.6 or higher. (note for older interpreter I've opened cachix/nixpkgs-python#17 that I plan to address one day). I've added support for manylinux too, but libraries like
If I name it Last but not least, for Using all this the following { pkgs, ... }: {
packages = [ pkgs.cairo ];
languages.python = {
enable = true;
venv.enable = true;
venv.requirements = ''
pillow
'';
};
} And test it using |
That's a possibility, but the issue is that there is no correct behaviour for If we were to patch ctypes... what about just introducing a separate environment variable to list search paths for |
I’m trying to run a Python project that uses
libnfc
innix-shell
. The code doesand for some strange reason this returns just
libnfc.so.5
. I’m not sure howfind_library
works, but the docs say:Unfortunately this doesn’t seem to work, even though
g++
successfully builds a C++ program that depends onlibnfc
. Any ideas why this is happening? Why isn’t it able to figure out the path tolibnfc
? Shouldn’tctypes.util.find_library
be patched in nixpkgs to avoid running weird programs and just check the environment variables?The text was updated successfully, but these errors were encountered: