当前位置: 首页 > 工具软件 > Annoy > 使用案例 >

pip install annoy 报错 error: command ‘gcc‘ failed with exit status 1

巫坚白
2023-12-01

annoy 是我需要安装目标 package 的一个依赖包,每次安装都发生报错,因此单独拎出来手动安装。

直接通过 pip install annoy 发生报错:error: command 'gcc' failed with exit status 1,这种报错很可能是因为 gcc 库版本过低造成,仅通过 pip install annoy 无法自动更新 gcc 库,之后尝试另外几种方式安装 annpy。

pip install annoy
# 命令日志
Collecting annoy
  Using cached annoy-1.17.1.tar.gz (647 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: annoy
  Building wheel for annoy (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [17 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.8
      creating build/lib.linux-x86_64-3.8/annoy
      copying annoy/__init__.py -> build/lib.linux-x86_64-3.8/annoy
      copying annoy/__init__.pyi -> build/lib.linux-x86_64-3.8/annoy
      copying annoy/py.typed -> build/lib.linux-x86_64-3.8/annoy
      running build_ext
      building 'annoy.annoylib' extension
      creating build/temp.linux-x86_64-3.8
      creating build/temp.linux-x86_64-3.8/src
      gcc -pthread -B /home/hanjiangang/anaconda3/envs/scenic/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/hanjiangang/anaconda3/envs/scenic/include -fPIC -O2 -isystem /home/hanjiangang/anaconda3/envs/scenic/include -fPIC -I/home/hanjiangang/anaconda3/envs/scenic/include/python3.8 -c src/annoymodule.cc -o build/temp.linux-x86_64-3.8/src/annoymodule.o -D_CRT_SECURE_NO_WARNINGS -fpermissive -march=native -O3 -ffast-math -fno-associative-math -DANNOYLIB_MULTITHREADED_BUILD -std=c++14
      cc1plus: error: unrecognized command line option "-std=c++14"
      cc1plus: warning: unrecognized command line option "-Wno-unused-result"
# 报错位置      
error: command 'gcc' failed with exit status 1
      [end of output]

尝试了以下几行代码,发生同样报错

pip install --user annoy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple annoy

之后尝试 conda install 方式安装,首先在 anaconda https://anaconda.org/ 中检索是否提供 annoy 包,找到之后通过 annaconda 提供代码进行安装。

conda install -c "conda-forge/label/gcc7" python-annoy

conda 会自动安装 annoy 并更新 gcc 库,安装完成后检查 gcc,发现版本变成了 gcc7

# 查看 annoy 是否成功安装
conda list | grep annoy
python-annoy              1.17.1           py38hfa26641_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

# 检查 gcc 版本
conda list | grep gcc
_libgcc_mutex             0.1                 conda_forge    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ca-certificates           2018.10.15           ha4d7672_0    conda-forge/label/gcc7
libgcc-ng                 12.2.0              h65d4601_19    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

虽然 gcc 升级到 gcc7,但系统环境默认的 gcc 库仍然是老版本,因此在系统环境中指向 gcc7,搜了很久也找不到方法,留待以后解决

# gcc 版本,仍然是老版本 gcc4
gcc -v
# 命令日志
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) 

# gcc 位置仍然是系统默认路径
which gcc
# 命令日志
/usr/bin/gcc
 类似资料: