annoy 是我需要安装目标 package 的一个依赖包,每次安装都发生报错,因此单独拎出来手动安装。
直接通过 pip install annoy 发生报错:error: command ‘gcc’ failed with exit status 1,这种报错很可能是因为 gcc 库版本过低造成,仅通过 pip install annoy 无法自动更新 gcc 库,之后尝试另外几种方式安装 annpy。
pip install annoy# 命令日志Collecting annoyUsing cached annoy-1.17.1.tar.gz (647 kB)Preparing metadata (setup.py) ... doneBuilding wheels for collected packages: annoyBuilding wheel for annoy (setup.py) ... errorerror: subprocess-exited-with-error× python setup.py bdist_wheel did not run successfully.│ exit code: 1╰─> [17 lines of output]running bdist_wheelrunning buildrunning build_pycreating buildcreating build/lib.linux-x86_64-3.8creating build/lib.linux-x86_64-3.8/annoycopying annoy/__init__.py -> build/lib.linux-x86_64-3.8/annoycopying annoy/__init__.pyi -> build/lib.linux-x86_64-3.8/annoycopying annoy/py.typed -> build/lib.linux-x86_64-3.8/annoyrunning build_extbuilding 'annoy.annoylib' extensioncreating build/temp.linux-x86_64-3.8creating build/temp.linux-x86_64-3.8/srcgcc -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++14cc1plus: 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 annoypip 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 annoypython-annoy1.17.1 py38hfa26641_0https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge# 检查 gcc 版本conda list | grep gcc_libgcc_mutex 0.1 conda_forgehttps://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forgeca-certificates 2018.10.15 ha4d7672_0conda-forge/label/gcc7libgcc-ng 12.2.0h65d4601_19https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
虽然 gcc 升级到 gcc7,但系统环境默认的 gcc 库仍然是老版本,因此在系统环境中指向 gcc7,搜了很久也找不到方法,留待以后解决
# gcc 版本,仍然是老版本 gcc4gcc -v# 命令日志Using built-in specs.Target: x86_64-redhat-linuxConfigured 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-linuxThread model: posixgcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) # gcc 位置仍然是系统默认路径which gcc# 命令日志/usr/bin/gcc