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

cffi cannot find libzmq.so #395

Closed
hydrogen18 opened this issue Aug 2, 2013 · 26 comments
Closed

cffi cannot find libzmq.so #395

hydrogen18 opened this issue Aug 2, 2013 · 26 comments

Comments

@hydrogen18
Copy link

I have installing libzmq in /home/ericu/local with the --prefix option on its configure script. Pyzmq installs fine under CPython 2.7.5. It does not work under pypy even with the environmental variables set.

ericu@ubuntu-lts-base:~/fairywren$ LIBRARY_PATH=/home/ericu/local/lib C_INCLUDE_PATH=/home/ericu/local/include pypy -c 'import zmq'
Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel
  File "app_main.py", line 566, in run_it
  File "<string>", line 1, in <module>
  File "/home/ericu/pypy-ericu/site-packages/zmq/__init__.py", line 52, in <module>
    from zmq.sugar import backend
  File "/home/ericu/pypy-ericu/site-packages/zmq/sugar/__init__.py", line 16, in <module>
    from zmq.sugar import (
  File "/home/ericu/pypy-ericu/site-packages/zmq/sugar/constants.py", line 16, in <module>
    from .backend import constants
  File "/home/ericu/pypy-ericu/site-packages/zmq/sugar/backend.py", line 29, in <module>
    from zmq.cffi_core import (
  File "/home/ericu/pypy-ericu/site-packages/zmq/cffi_core/__init__.py", line 12, in <module>
    from zmq.cffi_core import (constants, error, message, context, socket,
  File "/home/ericu/pypy-ericu/site-packages/zmq/cffi_core/constants.py", line 4, in <module>
    from ._cffi import C, constant_names, zmq_version_info
  File "/home/ericu/pypy-ericu/site-packages/zmq/cffi_core/_cffi.py", line 195, in <module>
    "Please check that you have zeromq headers and libraries." % e)
ImportError: PyZMQ CFFI backend couldn't find zeromq: cannot load library /home/ericu/pypy-ericu/site-packages/zmq/cffi_core/__pycache__/_cffi__g6ed94bfax67d4e236.pypy-21.so: libzmq.so.3: cannot open shared object file: No such file or directory
Please check that you have zeromq headers and libraries.
ericu@ubuntu-lts-base:~/fairywren$ 
@minrk
Copy link
Member

minrk commented Aug 2, 2013

Try setting:

LD_LIBRARY_PATH=/home/ericu/local/lib

@hydrogen18
Copy link
Author

It is not shown but it is set to that value.

@minrk
Copy link
Member

minrk commented Aug 2, 2013

Your paste suggests that you have LIBRARY_PATH set, but not LD_LIBRARY_PATH, is this accurate?

@hydrogen18
Copy link
Author

That is not accurate. I have it set in my profile when I login.

@minrk
Copy link
Member

minrk commented Aug 2, 2013

What do you get from this:

from cffi import FFI

def zmq_version_info():
    ffi = FFI()
    ffi.cdef('void zmq_version(int *major, int *minor, int *patch);')
    libzmq = ffi.verify('#include <zmq.h>',
                                            libraries=['c', 'zmq'])
    major = ffi.new('int*')
    minor = ffi.new('int*')
    patch = ffi.new('int*')

    libzmq.zmq_version(major, minor, patch)

    return (int(major[0]), int(minor[0]), int(patch[0]))

zmq_version_info()

@hydrogen18
Copy link
Author

Looks like the same thing.

ericu@ubuntu-lts-base:~$ echo $LD_LIBRARY_PATH
/home/ericu/local/lib
ericu@ubuntu-lts-base:~$ nano minrk.py
ericu@ubuntu-lts-base:~$ cat minrk.py
from cffi import FFI

def zmq_version_info():
    ffi_check = FFI()
    ffi_check.cdef('void zmq_version(int *major, int *minor, int *patch);')
    libzmq = ffi_check.verify('#include <zmq.h>',
                                            libraries=['c', 'zmq'])
    major = ffi.new('int*')
    minor = ffi.new('int*')
    patch = ffi.new('int*')

    libzmq.zmq_version(major, minor, patch)

    return (int(major[0]), int(minor[0]), int(patch[0]))

zmq_version_info()
ericu@ubuntu-lts-base:~$ LIBRARY_PATH=/home/ericu/local/lib/ C_INCLUDE_PATH=/home/ericu/local/include pypy minrk.py
Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel
  File "minrk.py", line 16, in <module>
    zmq_version_info()
  File "minrk.py", line 7, in zmq_version_info
    libraries=['c', 'zmq'])
  File "/home/ericu/pypy-ericu/lib_pypy/cffi/api.py", line 311, in verify
    lib = self.verifier.load_library()
  File "/home/ericu/pypy-ericu/lib_pypy/cffi/verifier.py", line 69, in load_library
    return self._load_library()
  File "/home/ericu/pypy-ericu/lib_pypy/cffi/verifier.py", line 143, in _load_library
    return self._vengine.load_library()
  File "/home/ericu/pypy-ericu/lib_pypy/cffi/vengine_gen.py", line 64, in load_library
    module = backend.load_library(self.verifier.modulefilename)
OSError: cannot load library /home/ericu/__pycache__/_cffi__g6ed94bfax67d4e236.pypy-21.so: libzmq.so.3: cannot open shared object file: No such file or directory
ericu@ubuntu-lts-base:~$ 

@minrk
Copy link
Member

minrk commented Aug 2, 2013

and what do you get from ls $LD_LIBRARY_PATH?

@hydrogen18
Copy link
Author

It looks like libzmq.so.3 is in there.

ericu@ubuntu-lts-base:~$ ls -l $LD_LIBRARY_PATH
total 21764
-r-xr-xr-x  1 ericu ericu 12971050 Jul 31 19:35 libpython2.7.a
-rw-r--r--  1 ericu ericu  6609546 Jul 31 19:38 libzmq.a
-rwxr-xr-x  1 ericu ericu      954 Jul 31 19:38 libzmq.la
lrwxrwxrwx  1 ericu ericu       15 Jul 31 19:38 libzmq.so -> libzmq.so.3.0.0
lrwxrwxrwx  1 ericu ericu       15 Jul 31 19:38 libzmq.so.3 -> libzmq.so.3.0.0
-rwxr-xr-x  1 ericu ericu  2670797 Jul 31 19:38 libzmq.so.3.0.0
drwxr-xr-x  2 ericu ericu     4096 Jul 31 19:38 pkgconfig
drwxr-xr-x 27 ericu ericu    20480 Jul 31 19:35 python2.7
ericu@ubuntu-lts-base:~$ 

@minrk
Copy link
Member

minrk commented Aug 2, 2013

Any change if you scrub /home/ericu/__pycache__?

@hydrogen18
Copy link
Author

I deleted the directory and I'm getting the same error.

@hydrogen18
Copy link
Author

Previously, I had done a ./configure --prefix=/home/ericu/local' when installing zeromq. I redid the install and did ./configure && sudo make install.

Now I get

ericu@ubuntu-lts-base:~$ pypy
Python 2.7.3 (480845e6b1dd219d0944e30f62b01da378437c6c, Aug 01 2013, 22:20:41)
[PyPy 2.1.0 with GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``Every time someone argues with
"Smalltalk has always done X", it is always a good hint that something needs to
be changed fast. - Marcus Denker''
>>>> import zmq
>>>> 

Your script on the other hand has a problem:

ericu@ubuntu-lts-base:~$ pypy minrk.py 
Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel
  File "minrk.py", line 16, in <module>
    zmq_version_info()
  File "minrk.py", line 8, in zmq_version_info
    major = ffi.new('int*')
NameError: global name 'ffi' is not defined
ericu@ubuntu-lts-base:~$ 

Additionally, this is my dev environment. In my production environment, I cannot install into /usr/local/lib and /usr/local/include . I would still like to figure out why it will not work when installed into /home/ericu/local

@minrk
Copy link
Member

minrk commented Aug 2, 2013

That NameError was just a typo from a bad copy/paste. Should be fixed above.

@minrk
Copy link
Member

minrk commented Aug 2, 2013

I'll try to get a test setup working without a system libzmq - it definitely should work (and does work great with CPython). Weirdly enough, all of the documentation I have read suggests that you are doing everything right.

@hydrogen18
Copy link
Author

Thanks. I appreciate you looking into the issue.

@minrk
Copy link
Member

minrk commented Aug 2, 2013

It looks like CFFI ignores [DY]LD_LIBRARY_PATH, but respects LIBRARY_PATH.

  • I removed libzmq from my system

  • in libzmq dir (fresh checkout of master): ./configure --prefix=/tmp/libzmq && make && make install

  • pip install pyzmq (gets 13.1.0)

  • pypy -c "import zmq; print zmq.zmq_version()" fails to find zmq.h

    env/pypy-cffi/site-packages/zmq/cffi_core/__pycache__/_cffi__g6ed94bfax67d4e236.c:25:10: fatal error: 'zmq.h' file not found
    #include <zmq.h>
    
  • C_INCLUDE_PATH=/tmp/libzmq/include pypy -c "import zmq; print zmq.zmq_version()" finds zmq.h, fails to link:

    ld: library not found for -lzmq
    
  • adding DYLD_LIBRARY_PATH=/tmp/libzmq/lib changes nothing (makes sense, because it only affects runtime loading, not compilation)

  • LIBRARY_PATH=/tmp/libzmq/lib C_INCLUDE_PATH=/tmp/libzmq/include pypy -c "import zmq; print zmq.zmq_version()" compiles successfully and prints 3.3.0.

This is with pypy-2.1.0 on OS X 10.8.4

@hydrogen18
Copy link
Author

OK, there must be something very different on Ubuntu. I guess I'l just hold off on pypy for now.

@felipecruz
Copy link
Member

@hydrogen18 I'm not sure if this affects custom prefixes installations, but in general, in linux, after make && sudo make install you must also run sudo ldconfig

The last example from @minrk LIBRARY_PATH=/tmp/libzmq/lib C_INCLUDE_PATH=/tmp/libzmq/include pypy -c "import zmq; print zmq.zmq_version()" should work

@hydrogen18
Copy link
Author

ldconfig only affects linkage defined in /etc/ld.so.conf

Current workaround is:

ericu@ubuntu-lts-base:~$ LD_PRELOAD=/home/ericu/local/lib/libzmq.so.3 pypy -c 'import zmq; print zmq.zmq_version_info()'
(3, 2, 3)
ericu@ubuntu-lts-base:~$ 

However, using LD_PRELOAD seems to me incredibly hackish.

@minrk
Copy link
Member

minrk commented Aug 2, 2013

I just ran my sequence above on Ubuntu LTS 12.04 (pypy-2.1.0), and it behaved the same as before. C_INCLUDE_PATH required to find the header, LIBRARY_PATH required to link, and LD_LIBRARY_PATH required at runtime. Note that after the first run which does the compilation, only LD_LIBRARY_PATH is required.

@hydrogen18
Copy link
Author

No idea why, but you are right. It only works if you pass in LD_LIBRARY_PATH when invoking pypy

ericu@ubuntu-lts-base:~$ LD_LIBRARY_PATH=/home/ericu/local/lib pypy
Python 2.7.3 (480845e6b1dd219d0944e30f62b01da378437c6c, Aug 01 2013, 22:20:41)
[PyPy 2.1.0 with GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``PyPy is too cool for
querystrings.''
>>>> import zmq
>>>> 
ericu@ubuntu-lts-base:~$ echo $LD_LIBRARY_PATH
/home/ericu/local/lib
ericu@ubuntu-lts-base:~$ pypy
Python 2.7.3 (480845e6b1dd219d0944e30f62b01da378437c6c, Aug 01 2013, 22:20:41)
[PyPy 2.1.0 with GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``Every time someone argues with
"Smalltalk has always done X", it is always a good hint that something needs to
be changed fast. - Marcus Denker''
>>>> import zmq
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ericu/pypy-ericu/site-packages/zmq/__init__.py", line 52, in <module>
    from zmq.sugar import backend
  File "/home/ericu/pypy-ericu/site-packages/zmq/sugar/__init__.py", line 16, in <module>
    from zmq.sugar import (
  File "/home/ericu/pypy-ericu/site-packages/zmq/sugar/constants.py", line 16, in <module>
    from .backend import constants
  File "/home/ericu/pypy-ericu/site-packages/zmq/sugar/backend.py", line 29, in <module>
    from zmq.cffi_core import (
  File "/home/ericu/pypy-ericu/site-packages/zmq/cffi_core/__init__.py", line 12, in <module>
    from zmq.cffi_core import (constants, error, message, context, socket,
  File "/home/ericu/pypy-ericu/site-packages/zmq/cffi_core/constants.py", line 4, in <module>
    from ._cffi import C, constant_names, zmq_version_info
  File "/home/ericu/pypy-ericu/site-packages/zmq/cffi_core/_cffi.py", line 195, in <module>
    "Please check that you have zeromq headers and libraries." % e)
ImportError: PyZMQ CFFI backend couldn't find zeromq: cannot load library /home/ericu/pypy-ericu/site-packages/zmq/cffi_core/__pycache__/_cffi__g6ed94bfax67d4e236.pypy-21.so: libzmq.so.3: cannot open shared object file: No such file or directory
Please check that you have zeromq headers and libraries.
>>>> 

@minrk
Copy link
Member

minrk commented Aug 3, 2013

what is the line that sets LD_LIBRARY_PATH in your bashrc?

@hydrogen18
Copy link
Author

In my .profile file

LD_LIBRARY_PATH=$HOME/local/lib
LIBRARY_PATH=/home/ericu/local/lib/ 
C_INCLUDE_PATH=/home/ericu/local/include

I really appreciate all your help with this.

@minrk
Copy link
Member

minrk commented Aug 3, 2013

Aha! You need to export LD_LIBRARY_PATH=... if you want the setting to persist with subprocesses, as opposed to just being a variable for the shell session. You can check this by checking the os.environ dict in Python to see what variables the process has available.

@hydrogen18
Copy link
Author

Got it! Thanks for all the help.

@klaussfreire
Copy link
Contributor

I have a similar issue, except it's different. The error is the same, and I can get it to work with LD_PRELOAD, the difference is I have zmq 2.1.7 installed on the system, and I built zmq 3.2.2 and installed it in /usr/local. Without LD_PRELOAD, the cffi backend seems to only find system libzmq. This applies at runtime after the first successful import, so it seems to be a matter with dynamic loading of the .so

Any ideas?

@hydrogen18
Copy link
Author

I recommend opening a separate issue. I did not have any actual library issues, but a misunderstanding of how environmental variables are passed along to child processes by the bash interpreter.

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

No branches or pull requests

4 participants