pip install编译成功后执行导入报错

Execution import error after success pip install compilation

我的烦恼

干净Ubuntu 16.04环境,我想安装使用Crossbar.io。

我已经从 ppa、virtualenv 安装了 pypy 并激活了一个新的 pypy virtualenv。

我在通过命令 pip install crossbar 安装 crossbar 时遇到了一些错误,但使用此构建命令解决了问题:

pip install --no-cache-dir --global-option=build_ext --global-option="-I/usr/include/python2.7" crossbar

现在用 crossbar version 启动 crossbar 时出现以下错误:

Traceback (most recent call last):
  File "/home/visiboost/gmm_pypy_env2/bin/crossbar", line 11, in <module>
    load_entry_point('crossbar==17.6.1.post3', 'console_scripts', 'crossbar')()
  File "/home/visiboost/gmm_pypy_env2/site-packages/pkg_resources/__init__.py", line 542, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/visiboost/gmm_pypy_env2/site-packages/pkg_resources/__init__.py", line 2569, in load_entry_point
    return ep.load()
  File "/home/visiboost/gmm_pypy_env2/site-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/home/visiboost/gmm_pypy_env2/site-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/visiboost/gmm_pypy_env2/site-packages/crossbar/controller/cli.py", line 62, in <module>
    from crossbar.controller.node import _read_release_pubkey, _read_node_pubkey
  File "/home/visiboost/gmm_pypy_env2/site-packages/crossbar/controller/node.py", line 44, in <module>
    from nacl.signing import SigningKey
  File "/home/visiboost/gmm_pypy_env2/site-packages/nacl/signing.py", line 19, in <module>
    import nacl.bindings
  File "/home/visiboost/gmm_pypy_env2/site-packages/nacl/bindings/__init__.py", line 17, in <module>
    from nacl.bindings.crypto_box import (
  File "/home/visiboost/gmm_pypy_env2/site-packages/nacl/bindings/crypto_box.py", line 18, in <module>
    from nacl._sodium import ffi, lib
ImportError: unable to load extension module '/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so': /home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so: undefined symbol: _Py_NoneStruct

我尝试在启动前通过设置环境变量添加路径但没有成功:

export LD_LIBRARY_PATH=/usr/lib/python2.7/config-x86_64-linux-gnu/:/usr/lib/x86_64-linux-gnu/

我的环境

ldd 在库失败时的结果:

ldd -r /home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so
    linux-vdso.so.1 =>  (0x00007fff31ddd000)
    libsodium.so.18 => /usr/lib/x86_64-linux-gnu/libsodium.so.18 (0x00007fe336153000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe335f0c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe335b41000)
    /lib64/ld-linux-x86-64.so.2 (0x0000564659a68000)
undefined symbol: _Py_NoneStruct    (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyObject_CallMethod   (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyEval_RestoreThread  (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyLong_FromVoidPtr    (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyArg_UnpackTuple (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyErr_Occurred    (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyImport_ImportModule (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyLong_FromUnsignedLong   (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyInt_FromLong    (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)
undefined symbol: PyEval_SaveThread (/home/visiboost/gmm_pypy_env2/site-packages/nacl/_sodium.pypy-41-x86_64-linux-gnu.so)

你有什么想法吗?

你不应该将 cpython headers 与 pypy 一起使用,所以 --global-option="-I/usr/include/python2.7" 是错误的。如文档所述 here and here 您可能需要安装 pypy-dev 包以便您可以使用 pypy 构建包,就像您需要 python-dev 使用 python.

构建包

编辑:查看横梁documentation,他们根本不推荐使用apt get,还推荐从源代码编译CPython,这就是为什么没有提到[=12] =] 包.

使用@mattip response 解决:通过 apt-get install pypy-dev 安装 pypy-dev 包并再次 运行 pip install 以使用好的库重建模块 pip install --no-cache-dir crossbar.

它现在很适合我!