如何将python gcc绑定到gcc 4.8版本?

时间:2016-12-16 06:34:06

标签: python c++ linux ubuntu gcc

我想安装一个依赖于pyrfr的自动sklearn包。

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

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

我通过以下方式安装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

正确设置了Defaut 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也没有),但google没什么帮助。

1 个答案:

答案 0 :(得分:1)

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

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

闷热很简单,只是

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++