无法在Python中导入ZMQ(安装问题) [英] Cannot import zmq in python (install issue)

查看:64
本文介绍了无法在Python中导入ZMQ(安装问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法在我的MacBook(OSX 10.9.1)上安装pyzmq

要运行的第一个调用:

sudo pip install pyzmq

出现找不到libzmq的错误,它似乎正在尝试编译捆绑版本:

jono@air:~ $ sudo pip install pyzmq
Password:
Downloading/unpacking pyzmq
  Downloading pyzmq-14.0.1.tar.gz (867kB): 867kB downloaded
  Running setup.py egg_info for package pyzmq

    no previously-included directories found matching 'docs/build'
    no previously-included directories found matching 'docs/gh-pages'
    warning: no directories found matching 'bundled/uuid'
    warning: no previously-included files found matching 'bundled/uuid/Makefile*'
    warning: no previously-included files found matching 'bundled/zeromq/src/Makefile*'
    warning: no previously-included files found matching 'bundled/zeromq/src/platform.hpp'
    warning: no previously-included files found matching 'setup.cfg'
    warning: no previously-included files found matching 'zmq/libzmq*'
    warning: no previously-included files matching '__pycache__/*' found anywhere in distribution
    warning: no previously-included files matching '.deps/*' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    warning: no previously-included files matching '*.pyd' found anywhere in distribution
    warning: no previously-included files matching '.git*' found anywhere in distribution
    warning: no previously-included files matching '.DS_Store' found anywhere in distribution
    warning: no previously-included files matching '.mailmap' found anywhere in distribution
Installing collected packages: pyzmq
  Running setup.py install for pyzmq
    Did not find libzmq via pkg-config:
    Package libzmq was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libzmq.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libzmq' found

    xcrun clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -c build/temp.macosx-10.8-x86_64-2.7/scratch/check_sys_un.c -o build/temp.macosx-10.8-x86_64-2.7/scratch/check_sys_un.o
    xcrun clang -undefined dynamic_lookup build/temp.macosx-10.8-x86_64-2.7/scratch/check_sys_un.o -o build/temp.macosx-10.8-x86_64-2.7/scratch/check_sys_un
    Configure: Autodetecting ZMQ settings...
        Custom ZMQ dir:
    ************************************************
    xcrun clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Izmq/utils -Izmq/backend/cython -Izmq/devices -c build/temp.macosx-10.8-x86_64-2.7/scratch/vers.c -o build/temp.macosx-10.8-x86_64-2.7/scratch/vers.o
    build/temp.macosx-10.8-x86_64-2.7/scratch/vers.c:4:10: fatal error: 'zmq.h' file not found
    #include "zmq.h"
             ^
    1 error generated.

    error: command 'xcrun' failed with exit status 1

    Failed with default libzmq, trying again with /usr/local
    Configure: Autodetecting ZMQ settings...
        Custom ZMQ dir:       /usr/local
    ************************************************
    xcrun clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -Izmq/utils -Izmq/backend/cython -Izmq/devices -c build/temp.macosx-10.8-x86_64-2.7/scratch/vers.c -o build/temp.macosx-10.8-x86_64-2.7/scratch/vers.o
    build/temp.macosx-10.8-x86_64-2.7/scratch/vers.c:4:10: fatal error: 'zmq.h' file not found
    #include "zmq.h"
             ^
    1 error generated.

    error: command 'xcrun' failed with exit status 1

    Warning: Failed to build or run libzmq detection test.

    If you expected pyzmq to link against an installed libzmq, please check to make sure:

        * You have a C compiler installed
        * A development version of Python is installed (including headers)
        * A development version of ZMQ >= 2.1.4 is installed (including headers)
        * If ZMQ is not in a default location, supply the argument --zmq=<path>
        * If you did recently install ZMQ to a default location,
          try rebuilding the ld cache with `sudo ldconfig`
          or specify zmq's location with `--zmq=/usr/local`

    If you expected to get a binary install (egg), we have those for
    current Pythons on OS X and Windows. These can be installed with
    easy_install, but PIP DOES NOT SUPPORT EGGS.

    You can skip all this detection/waiting nonsense if you know
    you want pyzmq to bundle libzmq as an extension by passing:

        `--zmq=bundled`

    I will now try to build libzmq as a Python extension
    unless you interrupt me (^C) in the next 10 seconds...

    ************************************************
 1...
    Using bundled libzmq
    already have bundled/zeromq
    attempting ./configure to generate platform.hpp
    Warning: failed to configure libzmq:
    /bin/sh: ./configure: No such file or directory

    staging platform.hpp from: buildutils/include_darwin
    ************************************************
    cc -c /tmp/crypto_box_keypairpmO9ft.c -o build/temp.macosx-10.8-x86_64-2.7/tmp/crypto_box_keypairpmO9ft.o
    /tmp/crypto_box_keypairpmO9ft.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
    main (int argc, char **argv) {
    ^~~~
    /tmp/crypto_box_keypairpmO9ft.c:2:5: warning: implicit declaration of function 'crypto_box_keypair' is invalid in C99 [-Wimplicit-function-declaration]
        crypto_box_keypair();
        ^
    2 warnings generated.
    cc build/temp.macosx-10.8-x86_64-2.7/tmp/crypto_box_keypairpmO9ft.o -lsodium -o build/temp.macosx-10.8-x86_64-2.7/a.out
    ld: library not found for -lsodium
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    Warning: libsodium not found, zmq.CURVE security will be unavailable
    ************************************************
    building 'zmq.libzmq' extension
    xcrun clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Ibundled/zeromq/include -Ibundled -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c buildutils/initlibzmq.c -o build/temp.macosx-10.8-x86_64-2.7/buildutils/initlibzmq.o
...
... (lots more compiling)
...
    xcrun clang -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk build/temp.macosx-10.8-x86_64-2.7/zmq/backend/cython/utils.o -o build/lib.macosx-10.8-x86_64-2.7/zmq/backend/cython/utils.so

    no previously-included directories found matching 'docs/build'
    no previously-included directories found matching 'docs/gh-pages'
    warning: no directories found matching 'bundled/uuid'
    warning: no previously-included files found matching 'bundled/uuid/Makefile*'
    warning: no previously-included files found matching 'bundled/zeromq/src/Makefile*'
    warning: no previously-included files found matching 'setup.cfg'
    warning: no previously-included files found matching 'zmq/libzmq*'
    warning: no previously-included files matching '__pycache__/*' found anywhere in distribution
    warning: no previously-included files matching '.deps/*' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    warning: no previously-included files matching '*.pyd' found anywhere in distribution
    warning: no previously-included files matching '.git*' found anywhere in distribution
    warning: no previously-included files matching '.DS_Store' found anywhere in distribution
    warning: no previously-included files matching '.mailmap' found anywhere in distribution
Successfully installed pyzmq
Cleaning up...

这不起作用:

jono@air:~ $ python
Python 2.7.3 (default, Mar 15 2013, 22:53:11) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zmq
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/zmq/__init__.py", line 35, in <module>
    _libzmq = ctypes.CDLL(bundled[0], mode=ctypes.RTLD_GLOBAL)
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/lib/python2.7/site-packages/zmq/libzmq.so, 10): Symbol not found: __ZNSiD0Ev
  Referenced from: /usr/local/lib/python2.7/site-packages/zmq/libzmq.so
  Expected in: flat namespace
 in /usr/local/lib/python2.7/site-packages/zmq/libzmq.so
>>> 

所以我将安装过程中的错误解释为没有libzmq。按照https://github.com/zeromq/pyzmq/wiki/Building-and-Installing-PyZMQ中的说明,我将其卸载,并尝试:

jono@air:~ $ brew install zeromq
==> Downloading http://download.zeromq.org/zeromq-3.2.3.tar.gz
######################################################################## 100.0%
==> Patching
patching file tests/test_disconnect_inproc.cpp
==> ./configure --prefix=/usr/local/Cellar/zeromq/3.2.3
==> make
==> make install
==> Caveats
To install the zmq gem on 10.6 with the system Ruby on a 64-bit machine,
you may need to do:

    ARCHFLAGS="-arch x86_64" gem install zmq -- --with-zmq-dir=/usr/local/opt/zeromq
==> Summary
🍺  /usr/local/Cellar/zeromq/3.2.3: 54 files, 2.4M, built in 52 seconds

后跟:

jono@air:~ $ sudo pip install pyzmq
Password:
Downloading/unpacking pyzmq
  Running setup.py egg_info for package pyzmq

    no previously-included directories found matching 'docs/build'
    no previously-included directories found matching 'docs/gh-pages'
    warning: no directories found matching 'bundled/uuid'
    warning: no previously-included files found matching 'bundled/uuid/Makefile*'
    warning: no previously-included files found matching 'bundled/zeromq/src/Makefile*'
    warning: no previously-included files found matching 'setup.cfg'
    warning: no previously-included files found matching 'zmq/libzmq*'
    warning: no previously-included files matching '__pycache__/*' found anywhere in distribution
    warning: no previously-included files matching '.deps/*' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    warning: no previously-included files matching '*.pyd' found anywhere in distribution
    warning: no previously-included files matching '.git*' found anywhere in distribution
    warning: no previously-included files matching '.DS_Store' found anywhere in distribution
    warning: no previously-included files matching '.mailmap' found anywhere in distribution
Installing collected packages: pyzmq
  Running setup.py install for pyzmq
    Using bundled libzmq
    already have bundled/zeromq
    already have platform.hpp
    ************************************************
    cc -c /tmp/crypto_box_keypairLbTEQR.c -o build/temp.macosx-10.8-x86_64-2.7/tmp/crypto_box_keypairLbTEQR.o
    /tmp/crypto_box_keypairLbTEQR.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
    main (int argc, char **argv) {
    ^~~~
    /tmp/crypto_box_keypairLbTEQR.c:2:5: warning: implicit declaration of function 'crypto_box_keypair' is invalid in C99 [-Wimplicit-function-declaration]
        crypto_box_keypair();
        ^
    2 warnings generated.
    cc build/temp.macosx-10.8-x86_64-2.7/tmp/crypto_box_keypairLbTEQR.o -lsodium -o build/temp.macosx-10.8-x86_64-2.7/a.out
    ld: library not found for -lsodium
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    Warning: libsodium not found, zmq.CURVE security will be unavailable
    ************************************************

    no previously-included directories found matching 'docs/build'
    no previously-included directories found matching 'docs/gh-pages'
    warning: no directories found matching 'bundled/uuid'
    warning: no previously-included files found matching 'bundled/uuid/Makefile*'
    warning: no previously-included files found matching 'bundled/zeromq/src/Makefile*'
    warning: no previously-included files found matching 'setup.cfg'
    warning: no previously-included files found matching 'zmq/libzmq*'
    warning: no previously-included files matching '__pycache__/*' found anywhere in distribution
    warning: no previously-included files matching '.deps/*' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    warning: no previously-included files matching '*.pyd' found anywhere in distribution
    warning: no previously-included files matching '.git*' found anywhere in distribution
    warning: no previously-included files matching '.DS_Store' found anywhere in distribution
    warning: no previously-included files matching '.mailmap' found anywhere in distribution
Successfully installed pyzmq
Cleaning up...

我一直收到错误:

>>> import zmq
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/zmq/__init__.py", line 35, in <module>
    _libzmq = ctypes.CDLL(bundled[0], mode=ctypes.RTLD_GLOBAL)
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/lib/python2.7/site-packages/zmq/libzmq.so, 10): Symbol not found: __ZNSiD0Ev
  Referenced from: /usr/local/lib/python2.7/site-packages/zmq/libzmq.so
  Expected in: flat namespace
 in /usr/local/lib/python2.7/site-packages/zmq/libzmq.so

不管我做什么。

推荐答案

经过很多努力,我回到了基础知识,并设法通过以下方式使其工作:

从源代码生成:

brew install zeromq
...
python setup.py configure --zmq=/usr/local/Cellar/zeromq/4.0.3/
...
sudo python setup.py install
...

sudo port install 
...

我不知道为什么标准方法不起作用,但至少我让pyzmq起作用了:)

这篇关于无法在Python中导入ZMQ(安装问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆