python3.6 安装cvxpy时显示error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

错误粘贴:
sudo pip install cvxpy

The directory ‘/home/liao/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.

The directory ‘/home/liao/.cache/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.

Collecting cvxpy

Downloading https://files.pythonhosted.org/packages/76/3c/4314c56be5b069f4d542046912d503a07c96b42c0b075ef0e32b48f8579f/cvxpy-1.0.10.tar.gz (900kB)

100% |████████████████████████████████| 901kB 194kB/s

Requirement already satisfied: osqp in /usr/local/lib/python3.6/dist-packages (from cvxpy) (0.4.1)

Collecting ecos>=2 (from cvxpy)

Downloading https://files.pythonhosted.org/packages/b6/b4/988b15513b13e8ea2eac65e97d84221ac515a735a93f046e2a2a3d7863fc/ecos-2.0.5.tar.gz (114kB)

100% |████████████████████████████████| 122kB 205kB/s

Collecting scs>=1.1.3 (from cvxpy)

Downloading https://files.pythonhosted.org/packages/b3/fd/6e01c4f4a69fcc6c3db130ba55572089e78e77ea8c0921a679f9da1ec04c/scs-2.0.2.tar.gz (133kB)

100% |████████████████████████████████| 143kB 130kB/s

Collecting multiprocess (from cvxpy)

Downloading https://files.pythonhosted.org/packages/7a/ee/b9bf3e171f936743758ef924622d8dd00516c5532b00a1210a09bce68325/multiprocess-0.70.6.1.tar.gz (1.4MB)

100% |████████████████████████████████| 1.4MB 113kB/s

Collecting fastcache (from cvxpy)

Downloading https://files.pythonhosted.org/packages/fb/98/93f2d36738868e8dd5a8dbfc918169b24658f63e5fa041fe000c22ae4f8b/fastcache-1.0.2.tar.gz

Requirement already satisfied: six in /usr/lib/python3/dist-packages (from cvxpy) (1.10.0)

Collecting toolz (from cvxpy)

Downloading https://files.pythonhosted.org/packages/14/d0/a73c15bbeda3d2e7b381a36afb0d9cd770a9f4adc5d1532691013ba881db/toolz-0.9.0.tar.gz (45kB)

100% |████████████████████████████████| 51kB 182kB/s

Requirement already satisfied: numpy>=1.14 in /usr/local/lib/python3.6/dist-packages (from cvxpy) (1.15.4)

Requirement already satisfied: scipy>=0.19 in /usr/local/lib/python3.6/dist-packages (from cvxpy) (1.1.0)

Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from osqp->cvxpy) (0.17.1)

Collecting dill>=0.2.8.1 (from multiprocess->cvxpy)

Downloading https://files.pythonhosted.org/packages/6f/78/8b96476f4ae426db71c6e86a8e6a81407f015b34547e442291cd397b18f3/dill-0.2.8.2.tar.gz (150kB)

100% |████████████████████████████████| 153kB 172kB/s

Installing collected packages: ecos, scs, dill, multiprocess, fastcache, toolz, cvxpy

Running setup.py install for ecos … error

Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-8p3hc5ya/ecos/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-8hl_34hh/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

copying src/ecos.py -> build/lib.linux-x86_64-3.6

running build_ext

building '_ecos' extension

creating build/temp.linux-x86_64-3.6

creating build/temp.linux-x86_64-3.6/src

creating build/temp.linux-x86_64-3.6/ecos

creating build/temp.linux-x86_64-3.6/ecos/external

creating build/temp.linux-x86_64-3.6/ecos/external/ldl

creating build/temp.linux-x86_64-3.6/ecos/external/ldl/src

creating build/temp.linux-x86_64-3.6/ecos/src

creating build/temp.linux-x86_64-3.6/ecos/external/amd

creating build/temp.linux-x86_64-3.6/ecos/external/amd/src

creating build/temp.linux-x86_64-3.6/ecos/ecos_bb

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYTHON -DDLONG -DLDL_LONG -DCTRLC=1 -Iecos/include -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -Iecos/external/amd/include -Iecos/external/ldl/include -Iecos/external/SuiteSparse_config -I/usr/include/python3.6m -c src/ecosmodule.c -o build/temp.linux-x86_64-3.6/src/ecosmodule.o

src/ecosmodule.c:4:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------

Command “/usr/bin/python -u -c “import setuptools, tokenize;file=’/tmp/pip-install-8p3hc5ya/ecos/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-8hl_34hh/install-record.txt --single-version-externally-managed --compile” failed with error code 1 in /tmp/pip-install-8p3hc5ya/ecos/

sudo apt-get install python3.6-dev
再重新pip install cvxpy 即可正确安装

1赞

good job

后续遇到错误也随手记录一下