在新环境中生成cython扩展:找不到/lib/libpthread.so.0

2024-07-02 11:24:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试部署一个使用一些cython扩展的包。我已经编写了以下安装脚本:

import os
import sys
from setuptools import setup, Extension

# factory function
def my_build_ext(pars):
    # import delayed:
    from setuptools.command.build_ext import build_ext as _build_ext

    # include_dirs adjusted: 
    class build_ext(_build_ext):
        def finalize_options(self):
            _build_ext.finalize_options(self)
            # Prevent numpy from thinking it is still in its setup process:
            __builtins__.__NUMPY_SETUP__ = False
            import numpy
            self.include_dirs.append(numpy.get_include())

    #object returned:
    return build_ext(pars)

# cython c++ extensions
extnames = [
    'npextc',
    'intquickheapdict',
    'FixedOrderedIntDict'
    ]

...

PATHADD = 'vemomoto_core/npcollections/'
PACKAGEADD = PATHADD.replace("/", ".")

ext = '.pyx'

extensions = [Extension(PACKAGEADD+name, [PATHADD+name+ext],
                        extra_compile_args=['-std=c++11', '-O3']+parcompileargs,
                        extra_link_args=parlinkargs,
                        )
              for name in extnames]
for e in extensions:
    e.language_level = 3
    e.language = 'c++'

setup(
    name="vemomoto_core_npcollections",
    version="0.9.0.a7",
    cmdclass={'build_ext' : my_build_ext},
    setup_requires=['numpy', 'setuptools>=18.0'],
    install_requires=['numpy', 'scipy'], 
    python_requires='>=3.6',
    packages=['vemomoto_core', PACKAGEADD[:-1]],
    ext_modules=extensions,
    package_data={
        '': ['*.pxd', '*.pyx', '*.c', '*.cpp'],
    },
    zip_safe=False,
)

当我通过在setup.py目录中执行pip install .来构建包时,只要我在默认环境中工作,一切都可以正常工作。但是,当我在新的测试环境中测试流程时,我得到了错误

    /home/user/anaconda3/envs/test37/compiler_compat/ld: cannot find /lib/libpthread.so.0
    /home/user/anaconda3/envs/test37/compiler_compat/ld: cannot find /usr/lib/libpthread_nonshared.a
    collect2: error: ld returned 1 exit status
    error: command 'g++' failed with exit status 1

(完整输出如下所示。)

我假设这里缺少一些依赖项,但我不知道如何找出它是什么,以及如何解决错误。我能做什么

完整错误消息:

Building wheels for collected packages: vemomoto-core-npcollections                                                                                                                                   [76/1898]
  Building wheel for vemomoto-core-npcollections (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/user/anaconda3/envs/test37/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-0_ns61r9/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-0_ns61r9/se
tup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-4zeu
yeay
       cwd: /tmp/pip-req-build-0_ns61r9/
  Complete output (49 lines):
  /home/user/anaconda3/envs/test37/lib/python3.7/site-packages/setuptools/dist.py:476: UserWarning: Normalizing '0.9.0.a1' to '0.9.0a1'
    normalized_version,
  running bdist_wheel
  running build
  running build_py
  package init file 'vemomoto_core/__init__.py' not found (or not a regular file)
  creating build
  creating build/lib.linux-x86_64-3.7
  creating build/lib.linux-x86_64-3.7/vemomoto_core
  creating build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/_setup_npextc.py -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/sparse3d.py -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/_setup_FixedOrderedIntDict.py -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/_FixedOrderedIntDict_reduce.py -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/__init__.py -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections                                                                                                      copying vemomoto_core/npcollections/_setup_intquickheapdict.py -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections                                                                                       copying vemomoto_core/npcollections/npext.py -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/_npextc_utils.py -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/__init__.pxd -> build/lib.linux-x86_64-3.7/vemomoto_core
  copying vemomoto_core/npcollections/FixedOrderedIntDict.pxd -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/npextc.pxd -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/intquickheapdict.pxd -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/intquickheapdict.pyx -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections                                                                                             copying vemomoto_core/npcollections/npextc.pyx -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/FixedOrderedIntDict.pyx -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/heapoperations_c.c -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/sectionsum.c -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections                                                                                                     copying vemomoto_core/npcollections/intquickheapdict.cpp -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections                                                                                             copying vemomoto_core/npcollections/FixedOrderedIntDict.cpp -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  copying vemomoto_core/npcollections/npextc.cpp -> build/lib.linux-x86_64-3.7/vemomoto_core/npcollections
  running build_ext
  building 'vemomoto_core.npcollections.npextc' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/vemomoto_core
  creating build/temp.linux-x86_64-3.7/vemomoto_core/npcollections                                                                                                                                               gcc -pthread -B /home/user/anaconda3/envs/test37/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/user/anaconda3/envs/test37/include/python3.7m -I/home/user/anaconda3/envs/test37/lib/python3.7/site-packages/numpy/core/include -c vemomoto_core/npcollections/npextc.cpp -o build/temp.linux-x86_64-3.7/vemomoto_core/npcollections/npextc.o -std=c++11 -O3 -fopenmp
  cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
  In file included from /home/user/anaconda3/envs/test37/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1832:0,
                   from /home/user/anaconda3/envs/test37/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                   from /home/user/anaconda3/envs/test37/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                   from vemomoto_core/npcollections/npextc.cpp:636:
  /home/user/anaconda3/envs/test37/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEP
RECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   #warning "Using deprecated NumPy API, disable it with " \
    ^~~~~~~
  g++ -pthread -shared -B /home/user/anaconda3/envs/test37/compiler_compat -L/home/user/anaconda3/envs/test37/lib -Wl,-rpath=/home/user/anaconda3/envs/test37/lib -Wl,--no-as-needed -Wl,--sysroot=
/ -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections build/temp.linux-x86_64-3.7/vemomoto_core/npcollections/npextc.o -o build/lib.linux-x86_64-3.7/ve
momoto_core/npcollections/npextc.cpython-37m-x86_64-linux-gnu.so -fopenmp
  /home/user/anaconda3/envs/test37/compiler_compat/ld: cannot find /lib/libpthread.so.0
  /home/user/anaconda3/envs/test37/compiler_compat/ld: cannot find /usr/lib/libpthread_nonshared.a
  collect2: error: ld returned 1 exit status
  error: command 'g++' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for vemomoto-core-npcollections
  Running setup.py clean for vemomoto-core-npcollections
Failed to build vemomoto-core-npcollections


Tags: pycorebuildhomelinuxlibextx86
1条回答
网友
1楼 · 发布于 2024-07-02 11:24:53

为了解决这个问题,我将新鲜的Python环境与我使用的环境进行了比较。为此,我使用

conda list

在旧的和新的安装和比较输出。然后我查找旧环境中包含但新环境中没有包含的包,这些包的名称表明它们可能包含正确的文件

在安装候选程序并重试构建之后,我发现gxx_linux-64(对于另一个包cmake)是构建的必要条件。由于这些包在PyPI上似乎不可用,我将要求最终用户使用anaconda命令

conda install gxx_linux-64
conda install cmake

在安装我的软件包之前。在安装脚本中包含此依赖项会很好,但这是另一个问题

相关问题 更多 >