简体   繁体   English

我无法在虚拟环境中为 Python 3.6 安装 CVXPY package

[英]I'm unable to install the CVXPY package for Python 3.6 in a virtual environment

I am trying to install the CVXPY package on a virtual environment for Python 3.6, on Linux Ubuntu 16.04.我正在尝试在 Python 3.6、Linux Ubuntu 16.04 的虚拟环境中安装 CVXPY package。

I started by creating a virtual environment:我首先创建一个虚拟环境:

python3.6 -m venv tutorial-env

I then followed the instructions here , and installed the following dependencies manually:然后我按照此处的说明进行操作,并手动安装了以下依赖项:

pip install numpy
pip install scipy

I then tried to download CVXPY:然后我尝试下载 CVXPY:

pip install cvxpy

But I get the following error:但我收到以下错误:

Collecting cvxpy
  Using cached cvxpy-1.1.7.tar.gz (1.0 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: osqp>=0.4.1 in ./tutorial-env/lib/python3.6/site-packages (from cvxpy) (0.6.1)
Requirement already satisfied: scipy>=1.1.0 in ./tutorial-env/lib/python3.6/site-packages (from cvxpy) (1.5.4)
Requirement already satisfied: numpy>=1.15 in ./tutorial-env/lib/python3.6/site-packages (from cvxpy) (1.19.4)
Requirement already satisfied: ecos>=2 in ./tutorial-env/lib/python3.6/site-packages (from cvxpy) (2.0.7.post1)
Collecting scs>=1.1.6
  Using cached scs-2.1.2.tar.gz (3.5 MB)
Requirement already satisfied: future in ./tutorial-env/lib/python3.6/site-packages (from osqp>=0.4.1->cvxpy) (0.18.2)
Using legacy 'setup.py install' for scs, since package 'wheel' is not installed.
Building wheels for collected packages: cvxpy
  Building wheel for cvxpy (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/[username]/tutorial-env/bin/python3.6 /home/[username]/tutorial-env/lib/python3.6/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmpehj5rzra
       cwd: /tmp/pip-install-bu874zhr/cvxpy
  Complete output (426 lines):
  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/cvxpy
  copying cvxpy/__init__.py -> build/lib.linux-x86_64-3.6/cvxpy
  copying cvxpy/error.py -> build/lib.linux-x86_64-3.6/cvxpy
  copying cvxpy/settings.py -> build/lib.linux-x86_64-3.6/cvxpy
  [....cut for length...]
  running build_ext
  building '_cvxcore' extension
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/cvxpy
  creating build/temp.linux-x86_64-3.6/cvxpy/cvxcore
  creating build/temp.linux-x86_64-3.6/cvxpy/cvxcore/src
  creating build/temp.linux-x86_64-3.6/cvxpy/cvxcore/python
  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 -Icvxpy/cvxcore/src/ -Icvxpy/cvxcore/python/ -Icvxpy/cvxcore/include/ -I/home/[username]/tutorial-env/include -I/usr/include/python3.6m -I/tmp/pip-build-env-7cso5slq/overlay/lib/python3.6/site-packages/numpy/core/include -c cvxpy/cvxcore/src/cvxcore.cpp -o build/temp.linux-x86_64-3.6/cvxpy/cvxcore/src/cvxcore.o -O3
  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 -Icvxpy/cvxcore/src/ -Icvxpy/cvxcore/python/ -Icvxpy/cvxcore/include/ -I/home/[username]/tutorial-env/include -I/usr/include/python3.6m -I/tmp/pip-build-env-7cso5slq/overlay/lib/python3.6/site-packages/numpy/core/include -c cvxpy/cvxcore/src/LinOpOperations.cpp -o build/temp.linux-x86_64-3.6/cvxpy/cvxcore/src/LinOpOperations.o -O3
  cvxpy/cvxcore/src/LinOpOperations.cpp: In function ‘Tensor get_rmul_mat(const LinOp&, int)’:
  cvxpy/cvxcore/src/LinOpOperations.cpp:717:7: warning: variable ‘arg_cols’ set but not used [-Wunused-but-set-variable]
     int arg_cols;
         ^
  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 -Icvxpy/cvxcore/src/ -Icvxpy/cvxcore/python/ -Icvxpy/cvxcore/include/ -I/home/[username]/tutorial-env/include -I/usr/include/python3.6m -I/tmp/pip-build-env-7cso5slq/overlay/lib/python3.6/site-packages/numpy/core/include -c cvxpy/cvxcore/src/Utils.cpp -o build/temp.linux-x86_64-3.6/cvxpy/cvxcore/src/Utils.o -O3
  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 -Icvxpy/cvxcore/src/ -Icvxpy/cvxcore/python/ -Icvxpy/cvxcore/include/ -I/home/[username]/tutorial-env/include -I/usr/include/python3.6m -I/tmp/pip-build-env-7cso5slq/overlay/lib/python3.6/site-packages/numpy/core/include -c cvxpy/cvxcore/python/cvxcore_wrap.cpp -o build/temp.linux-x86_64-3.6/cvxpy/cvxcore/python/cvxcore_wrap.o -O3
  cvxpy/cvxcore/python/cvxcore_wrap.cpp:178:21: fatal error: Python.h: No such file or directory
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for cvxpy
Failed to build cvxpy
ERROR: Could not build wheels for cvxpy which use PEP 517 and cannot be installed directly

Pastebin with the full error message.带有完整错误消息的 Pastebin。

I have CVXPY installed and working on Python 3.5.2.我安装了 CVXPY 并在 Python 3.5.2 上工作。 I'm not sure why I'm having so much trouble getting it to work on Python 3.6.12.我不确定为什么要让它在 Python 3.6.12 上运行时遇到这么多麻烦。 I tried to install the dependencies OSQP, ECOS and SCS manually before trying to install CVXPY, but SCS throws up the same sort of error (Failed building wheel for SCS).在尝试安装 CVXPY 之前,我尝试手动安装依赖项 OSQP、ECOS 和 SCS,但是 SCS 抛出了同样的错误(SCS 的构建轮失败)。

I have no idea what this means, and I can't make heads or tails of this.我不知道这意味着什么,也无法弄清楚这件事的来龙去脉。 Any help is appreciated.任何帮助表示赞赏。

EDIT: So I did what one of the comments suggested, and installed the following:编辑:所以我做了其中一条评论的建议,并安装了以下内容:

pip install wheel

But I'm still getting an error.但我仍然遇到错误。

I tried to install the dependency by cloning the git repository, but nothing changes.我尝试通过克隆 git 存储库来安装依赖项,但没有任何变化。

(tutorial-env) [username]@CS:~$ git clone https://github.com/cvxgrp/cvxpy
Cloning into 'cvxpy'...
remote: Enumerating objects: 169, done.
remote: Counting objects: 100% (169/169), done.
remote: Compressing objects: 100% (124/124), done.
remote: Total 58970 (delta 90), reused 75 (delta 41), pack-reused 58801
Receiving objects: 100% (58970/58970), 168.74 MiB | 6.17 MiB/s, done.
Resolving deltas: 100% (40842/40842), done.
Checking connectivity... done.
(tutorial-env) [username]@CS:~$ cd ~/cvxpy
(tutorial-env) [username]@CS:~/cvxpy$ pip install -e .
Obtaining file:///home/[username]/cvxpy
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.15 in /home/[username]/tutorial-env/lib/python3.6/site-packages (from cvxpy==1.1.7) (1.19.4)
Requirement already satisfied: osqp>=0.4.1 in /home/[username]/tutorial-env/lib/python3.6/site-packages (from cvxpy==1.1.7) (0.6.1)
Requirement already satisfied: ecos>=2 in /home/[username]/tutorial-env/lib/python3.6/site-packages (from cvxpy==1.1.7) (2.0.7.post1)
Collecting scs>=1.1.6
  Using cached scs-2.1.2.tar.gz (3.5 MB)
Requirement already satisfied: scipy>=1.1.0 in /home/[username]/tutorial-env/lib/python3.6/site-packages (from cvxpy==1.1.7) (1.5.4)
Requirement already satisfied: future in /home/[username]/tutorial-env/lib/python3.6/site-packages (from osqp>=0.4.1->cvxpy==1.1.7) (0.18.2)
Building wheels for collected packages: scs
  Building wheel for scs (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/[username]/tutorial-env/bin/python3.6 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2yhxymp8/scs/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2yhxymp8/scs/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-xrktv9lx
       cwd: /tmp/pip-install-2yhxymp8/scs/

[snipped for length]

error: Command "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 -DCTRLC=1 -DDLONG=1 -DCOPYAMATRIX -DUSE_LAPACK -DHAVE_CBLAS -DHAVE_CBLAS -Iscs/include -Iscs/linsys -Iscs/linsys/cpu/direct/ -Iscs/linsys/external/amd -Iscs/linsys/external/dqlql -I/home/[username]/tutorial-env/lib/python3.6/site-packages/numpy/core/include -I/home/[username]/tutorial-env/include -I/usr/include/python3.6m -c src/scsmodule.c -o build/temp.linux-x86_64-3.6/src/scsmodule.o -O3" failed with exit status 1

----------------------------------------
  ERROR: Failed building wheel for scs
  Running setup.py clean for scs
Failed to build scs
Installing collected packages: scs, cvxpy
    Running setup.py install for scs ... error
    ERROR: Command errored out with exit status 1:
     command: /home/[username]/tutorial-env/bin/python3.6 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2yhxymp8/scs/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2yhxymp8/scs/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-yr_7wj14/install-record.txt --single-version-externally-managed --compile --install-headers /home/[username]/tutorial-env/include/site/python3.6/scs
         cwd: /tmp/pip-install-2yhxymp8/scs/
    Complete output (115 lines):

[snipped for length]

 error: Command "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 -DCTRLC=1 -DDLONG=1 -DCOPYAMATRIX -DUSE_LAPACK -DHAVE_CBLAS -DHAVE_CBLAS -Iscs/include -Iscs/linsys -Iscs/linsys/cpu/direct/ -Iscs/linsys/external/amd -Iscs/linsys/external/dqlql -I/home/[username]/tutorial-env/lib/python3.6/site-packages/numpy/core/include -I/home/[username]/tutorial-env/include -I/usr/include/python3.6m -c src/scsmodule.c -o build/temp.linux-x86_64-3.6/src/scsmodule.o -O3" failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/[username]/tutorial-env/bin/python3.6 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2yhxymp8/scs/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2yhxymp8/scs/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-yr_7wj14/install-record.txt --single-version-externally-managed --compile --install-headers /home/[username]/tutorial-env/include/site/python3.6/scs Check the logs for full command output.

Pastebin with full error message .带有完整错误消息的 Pastebin

I then tried to install the SCS dependency on its own first, but still, the same sort of error.然后我尝试先自行安装 SCS 依赖项,但仍然出现同样的错误。 Pastebin with full error message .带有完整错误消息的 Pastebin

**FIXED. **固定的。

After doing what @Czaporka suggested, and installing wheels using pip:在按照@Czaporka 的建议进行操作并使用 pip 安装轮子之后:

pip install wheels

the error message continued to persist.错误消息继续存在。 The problem was identified with the following line in the complete error message:完整错误消息中的以下行标识了该问题:

fatal error: Python.h: No such file or directory
  compilation terminated.

The way to resolve this error message was outlined in this answer .此答案中概述了解决此错误消息的方法。 Running the following on the Linux terminal fixed the issue:在 Linux 终端上运行以下命令修复了问题:

sudo apt-get install python3.6-dev

And I was able to go ahead and install CVXPY using pip with no further issues.而且我能够提前 go 并使用 pip 安装 CVXPY,没有其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM