Installing tsne in Google Colab notebook: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Installing tsne in Google Colab notebook: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

我正在尝试在 Google Colab 笔记本中安装 tsne 库。基于其他问题,我尝试安装以下无济于事:

!apt-get install libblas-dev libatlas-base-dev libxml2-dev libxslt1-dev gcc python-dev build-essential autoconf libtool pkg-config python-opengl python-imaging python-pyrex python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script libqt4-network libqt4-dbus python-qt4 python-qt4-gl libgle3 python-dev

!easy_install greenlet
!easy_install gevent

我收到以下错误:

Collecting tsne
  Using cached https://files.pythonhosted.org/packages/6f/0e/a214e3bf495605c283223a42f1c494ce6f601dcb0864e922cde50c1b8d0b/tsne-0.1.7.tar.gz
Requirement already satisfied: Cython>=0.19.1 in /usr/local/lib/python3.6/dist-packages (from tsne) (0.28.2)
Requirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python3.6/dist-packages (from tsne) (1.14.3)
Requirement already satisfied: scipy>=0.12.0 in /usr/local/lib/python3.6/dist-packages (from tsne) (0.19.1)
Building wheels for collected packages: tsne
  Running setup.py bdist_wheel for tsne ... - \ error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-te9lpc5e/tsne/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/pip-wheel-_thlgr71 --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/tsne
  copying tsne/__init__.py -> build/lib.linux-x86_64-3.6/tsne
  copying tsne/_version.py -> build/lib.linux-x86_64-3.6/tsne
  creating build/lib.linux-x86_64-3.6/tsne/tests
  copying tsne/tests/__init__.py -> build/lib.linux-x86_64-3.6/tsne/tests
  copying tsne/tests/test_seed.py -> build/lib.linux-x86_64-3.6/tsne/tests
  copying tsne/tests/test_iris.py -> build/lib.linux-x86_64-3.6/tsne/tests
  UPDATING build/lib.linux-x86_64-3.6/tsne/_version.py
  set build/lib.linux-x86_64-3.6/tsne/_version.py to '0.1.7'
  running build_ext
  building 'bh_sne' extension
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/tsne
  creating build/temp.linux-x86_64-3.6/tsne/bh_sne_src
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I/usr/local/include -Itsne/bh_sne_src/ -I/usr/include/python3.6m -c tsne/bh_sne.cpp -o build/temp.linux-x86_64-3.6/tsne/bh_sne.o -msse2 -O3 -fPIC -w
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I/usr/local/include -Itsne/bh_sne_src/ -I/usr/include/python3.6m -c tsne/bh_sne_src/quadtree.cpp -o build/temp.linux-x86_64-3.6/tsne/bh_sne_src/quadtree.o -msse2 -O3 -fPIC -w
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  In file included from tsne/bh_sne_src/quadtree.cpp:15:0:
  tsne/bh_sne_src/quadtree.h: In function ‘double abs(double)’:
  tsne/bh_sne_src/quadtree.h:17:34: error: ‘double abs(double)’ conflicts with a previous declaration
   static inline double abs(double x) { return (x < .0 ? -x : x); }
                                    ^
  In file included from /usr/include/c++/7/cmath:47:0,
                   from /usr/include/c++/7/math.h:36,
                   from tsne/bh_sne_src/quadtree.cpp:10:
  /usr/include/c++/7/bits/std_abs.h:70:3: note: previous declaration ‘constexpr double std::abs(double)’
     abs(double __x)
     ^~~
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for tsne
  Running setup.py clean for tsne
Failed to build tsne
Installing collected packages: tsne
  Running setup.py install for tsne ... - \ error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-te9lpc5e/tsne/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-record-f8u2da14/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/tsne
    copying tsne/__init__.py -> build/lib.linux-x86_64-3.6/tsne
    copying tsne/_version.py -> build/lib.linux-x86_64-3.6/tsne
    creating build/lib.linux-x86_64-3.6/tsne/tests
    copying tsne/tests/__init__.py -> build/lib.linux-x86_64-3.6/tsne/tests
    copying tsne/tests/test_seed.py -> build/lib.linux-x86_64-3.6/tsne/tests
    copying tsne/tests/test_iris.py -> build/lib.linux-x86_64-3.6/tsne/tests
    UPDATING build/lib.linux-x86_64-3.6/tsne/_version.py
    set build/lib.linux-x86_64-3.6/tsne/_version.py to '0.1.7'
    running build_ext
    building 'bh_sne' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/tsne
    creating build/temp.linux-x86_64-3.6/tsne/bh_sne_src
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I/usr/local/include -Itsne/bh_sne_src/ -I/usr/include/python3.6m -c tsne/bh_sne.cpp -o build/temp.linux-x86_64-3.6/tsne/bh_sne.o -msse2 -O3 -fPIC -w
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I/usr/local/include -Itsne/bh_sne_src/ -I/usr/include/python3.6m -c tsne/bh_sne_src/quadtree.cpp -o build/temp.linux-x86_64-3.6/tsne/bh_sne_src/quadtree.o -msse2 -O3 -fPIC -w
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    In file included from tsne/bh_sne_src/quadtree.cpp:15:0:
    tsne/bh_sne_src/quadtree.h: In function ‘double abs(double)’:
    tsne/bh_sne_src/quadtree.h:17:34: error: ‘double abs(double)’ conflicts with a previous declaration
     static inline double abs(double x) { return (x < .0 ? -x : x); }
                                      ^
    In file included from /usr/include/c++/7/cmath:47:0,
                     from /usr/include/c++/7/math.h:36,
                     from tsne/bh_sne_src/quadtree.cpp:10:
    /usr/include/c++/7/bits/std_abs.h:70:3: note: previous declaration ‘constexpr double std::abs(double)’
       abs(double __x)
       ^~~
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-te9lpc5e/tsne/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-record-f8u2da14/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-te9lpc5e/tsne/

I am trying to install the tsne library in a Google Colab notebook

看起来像一些 Debian 或 Ubuntu OS。 Ubuntu 18.04、python2 python3:

的示例
sudo apt install g++-5
cd tsne-0.1.7/
export CC=gcc-5
python setup.py build
python3 setup.py build

sudo su
export CC=gcc-5
python setup.py install
python3 setup.py install
exit

find /usr/local/lib/ -iname "*tsne*"
/usr/local/lib/python2.7/dist-packages/tsne-0.1.7-py2.7-linux-x86_64.egg
/usr/local/lib/python3.6/dist-packages/tsne-0.1.7-py3.6-linux-x86_64.egg
/usr/local/lib/python3.6/dist-packages/tsne-0.1.7-py3.6-linux-x86_64.egg/tsne

注意:一些 C 文件似乎包含旧代码,因此是 gcc-5。 C++ 代码适用于 g++-7。

sudo pip install tsne
Requirement already satisfied: tsne in ./python2.7/dist-packages/tsne-0.1.7-py2.7-linux-x86_64.egg

sudo pip3 install tsne
Requirement already satisfied: tsne in ./python3.6/dist-packages/tsne-0.1.7-py3.6-linux-x86_64.egg

注2:参考。 https://github.com/danielfrg/tsne → →

Scikit-learn v0.17 includes TSNE algorithms and you should probably be using them instead of this.


EDIT :这里的罪魁祸首似乎是 easy_install :如果你使用过 $ sudo pip3 install greenlet gevent 那么没有tsne 需要/已安装。