You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Amazon EC2实例安装Python包报错求助:preshed/blis编译失败

解决Python包安装时preshed、blis编译失败问题

问题背景

尝试从requirements.txt安装Python包时,preshed、blis等包编译报错,提示/usr/bin/x86_64-linux-gnu-gcc执行失败。当前环境为64位Python 3.7.9,需明确预安装的依赖及解决步骤。

错误日志

/tmp/pip-install-aw5ivhl1/blis_f463d355a4f44a76bf2cb429c1a0aa28/blis/_src/include/linux-x86_64/blis.h:1644:13: warning: ‘bli_obj_init_subpart_from’ defined but not used [-Wunused-function]
             1644 | static void bli_obj_init_subpart_from( obj_t* a, obj_t* b )
                  |             ^~~~~~~~~~~~~~~~~~~~~~~~~
            error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for blis
        Running setup.py clean for blis
      Failed to build preshed thinc blis
      Installing collected packages: wasabi, plac, cymem, wheel, tqdm, srsly, setuptools, preshed, numpy, murmurhash, Cython, blis, thinc
        Running setup.py install for preshed: started
        Running setup.py install for preshed: finished with status 'error'
        error: subprocess-exited-with-error

        × Running setup.py install for preshed did not run successfully.
        │ exit code: 1
        ╰─> [14 lines of output]
            /home/ubuntu/.local/lib/python3.10/site-packages/setuptools/__init__.py:85: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated. Requirements should be satisfied by a PEP 517 installer. If you are using pip, you can try `pip install --use-pep517`.
              dist.fetch_build_eggs(dist.setup_requires)
            running install
            /home/ubuntu/.local/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
              warnings.warn(
            running build
            running build_py
            running build_ext
            building 'preshed.maps' extension
            x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/usr/include/python3.10 -I/usr/include/python3.10 -c preshed/maps.cpp -o build/temp.linux-x86_64-cpython-310/preshed/maps.o -O3 -Wno-strict-prototypes -Wno-unused-function
            cc1plus: warning: command-line option ‘-Wno-strict-prototypes’ is valid for C/ObjC but not for C++
            cc1plus: fatal error: preshed/maps.cpp: No such file or directory
            compilation terminated.
            error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: legacy-install-failure

      × Encountered error while trying to install package.
      ╰─> preshed

      note: This is an issue with the package mentioned above, not pip.
      hint: See above for output from the failure.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

解决步骤

1. 安装系统编译依赖

编译C/C++扩展包需要基础编译工具和Python开发库,在Debian/Ubuntu系统执行以下命令:

sudo apt-get update && sudo apt-get install -y build-essential python3.7-dev libopenblas-dev
  • build-essential:包含gcc、g++等核心编译工具
  • python3.7-dev:Python 3.7的头文件和开发库,用于编译Python扩展
  • libopenblas-dev:BLAS线性代数库,blis包编译依赖

2. 升级pip、setuptools和wheel

错误日志提示setup.py安装已过时,需升级到符合PEP517标准的工具链:

pip install --upgrade pip setuptools wheel

3. 使用PEP517标准安装依赖

通过--use-pep517参数绕过旧的setup.py安装流程,改用现代构建方式:

pip install --use-pep517 -r requirements.txt

4. 指定兼容Python3.7的包版本

Python3.7属于较旧版本,部分新包版本不再兼容,可修改requirements.txt指定兼容版本:

  • preshed:指定preshed<=3.0.8
  • blis:指定blis<=0.7.9
  • thinc:指定thinc<=8.0.17

修改后重新执行安装命令即可。

5. 尝试预编译二进制轮子安装(可选)

若编译仍失败,可直接安装预编译的二进制包,避免本地编译:

pip install --only-binary :all: -r requirements.txt

内容的提问来源于stack exchange,提问作者TECH FREEKS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 13:29:57