python - 如何将 python gcc 绑定(bind)更改为 gcc 4.8 版本?

标签 python c++ linux ubuntu gcc

我想安装一个依赖于 pyrfr 的 auto-sklearn 包。

安装命令是 curl https://raw.githubusercontent.com/automl/auto-sklearn/master/requirements.txt | xargs -n 1 -L 1 pip 安装.

我的环境:安装了 gcc 4.8 和 g++ 4.8 的 ubuntu 12.04,python3.5-dev(在 virtualenv 中)。

我通过以下方式安装 gcc 和 g++:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update

sudo apt-get install gcc-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50

默认 gcc 设置正确:

➜  ~ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.1-2ubuntu1~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)

但我发现 python shell 仍然显示 [GCC 4.6.3]:

➜  ~ python
Python 3.5.2 (default, Jul 17 2016, 17:38:18)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

安装pyrfr 还是说(因为需要gcc 4.7或以上):

cc1plus: error: unrecognized command line option ‘-std=c++11’
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

更详细的错误日志:

Collecting pyrfr
  Downloading http://mirrors.aliyun.com/pypi/packages/95/90/95f77f76c2e3d44577ff2b96b0d365429797d9f83632b84d2c91d2b7a73a/pyrfr-0.2.0.tar.gz (340kB)
    100% |████████████████████████████████| 348kB 4.9MB/s
Building wheels for collected packages: pyrfr
  Running setup.py bdist_wheel for pyrfr ... error
  Complete output from command /root/.virtualenvs/py35/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-wt1wfz_q/pyrfr/setup.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/tmpcdvohh34pip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.5
  creating build/lib.linux-x86_64-3.5/pyrfr
  copying pyrfr/__init__.py -> build/lib.linux-x86_64-3.5/pyrfr
  running build_ext
  building 'pyrfr.regression' extension
  creating build/temp.linux-x86_64-3.5
  creating build/temp.linux-x86_64-3.5/pyrfr
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I./include -I/root/.virtualenvs/py35/lib/python3.5/site-packages/numpy/core/include -I/usr/include/python3.5m -I/root/.virtualenvs/py35/include/python3.5m -c pyrfr/regression.cpp -o build/temp.linux-x86_64-3.5/pyrfr/regression.o -O2 -std=c++11
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
  cc1plus: error: unrecognized command line option ‘-std=c++11’
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for pyrfr
  Running setup.py clean for pyrfr
Failed to build pyrfr
Installing collected packages: pyrfr
  Running setup.py install for pyrfr ... error
    Complete output from command /root/.virtualenvs/py35/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-wt1wfz_q/pyrfr/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-qrvy2ohy-record/install-record.txt --single-version-externally-managed --compile --install-headers /root/.virtualenvs/py35/include/site/python3.5/pyrfr:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    creating build/lib.linux-x86_64-3.5/pyrfr
    copying pyrfr/__init__.py -> build/lib.linux-x86_64-3.5/pyrfr
    running build_ext
    building 'pyrfr.regression' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/pyrfr
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I./include -I/root/.virtualenvs/py35/lib/python3.5/site-packages/numpy/core/include -I/usr/include/python3.5m -I/root/.virtualenvs/py35/include/python3.5m -c pyrfr/regression.cpp -o build/temp.linux-x86_64-3.5/pyrfr/regression.o -O2 -std=c++11
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
    cc1plus: error: unrecognized command line option ‘-std=c++11’
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/root/.virtualenvs/py35/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-wt1wfz_q/pyrfr/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-qrvy2ohy-record/install-record.txt --single-version-externally-managed --compile --install-headers /root/.virtualenvs/py35/include/site/python3.5/pyrfr" failed with error code 1 in /tmp/pip-build-wt1wfz_q/pyrfr/

我认为关键问题是 python3.5 没有链接到 gcc-4.8(甚至系统默认的 python2.7 也不是),但谷歌帮助不大。

最佳答案

最后我找到了解决方案.. 发现 x86_64-linux-gnu-gcc 是一个命令,虽然它看起来不像一个命令...

ubuntu 12 上的 python 似乎不会使用 /usr/bin/x86_64-linux-gnu-gcc(链接到 /usr/bin/gcc-4.6)而不是 /usr/bin/gcc,我完全不明白他们为什么这样做......

sulotion很简单,就是

cd /usr/bin
rm x86_64-linux-gnu-gcc
ln -sf gcc-4.8 x86_64-linux-gnu-gcc

如果你想改变g++和cpp,也可以

rm x86_64-linux-gnu-cpp
ln -sf cpp-4.8 x86_64-linux-gnu-cpp
rm x86_64-linux-gnu-g++
ln -sf g++-4.8 x86_64-linux-gnu-g++

关于python - 如何将 python gcc 绑定(bind)更改为 gcc 4.8 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41178564/

相关文章:

C++ 函数检查 char 是否为大写字母并计算给定字符串中大写字母的数量

linux - vdebug-vim : not working

python - 通过 Python API 客户端发送到 BigQuery 时验证查询出现语法错误

python - 我可以使用抽象方法来导入 (Python) Pandas 数据的特定于文件的格式吗?

c++ - 对 m128 的数组 [8] 使用 alignas(16) 是否正确?

Linux 使用 'nested' 字段排序

linux - 从另一个脚本调用一个 shell 脚本并将该脚本的输出存储在一个变量中

python - 返回按两个分组的字符串字母列表

python - 返回两个带有函数参数的值

iphone - (iphone) 可以为 C++ 类/结构定义 @property 吗?