在virtualenv中安装python开发人员

在virtualenv中安装python开发人员,python,installation,virtualenv,Python,Installation,Virtualenv,我正在尝试在我的virtualenv中安装mysqlclient for python。它在以下情况下失败: #include "Python.h" ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 经过一些研究,我发现我需要安装python开发人员。我已将其安装在我的主目录(即/usr/bin…)中,但未安装virtualen

我正在尝试在我的virtualenv中安装mysqlclient for python。它在以下情况下失败:

 #include "Python.h"

                ^

compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
经过一些研究,我发现我需要安装python开发人员。我已将其安装在我的主目录(即/usr/bin…)中,但未安装virtualenv,但每次我键入:

sudo apt-get install python-dev
我得到以下回应:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 453 not upgraded.

显示其可用性,在virtualenv之外,mysqlclient可以正确安装。问题是如何将python-dev安装纠正到virtualenv中,这是因为virtualenv没有将include和lib目录链接到virtualenv的目录。我使用anaconda虚拟环境解决了这个问题。
希望有帮助。

在Ubuntu 16.04上,我成功地使用python3-dev设置了Python虚拟环境。

也许不是最好的方法,但我的解决方案是安装。您也可以尝试更大的蟒蛇分布。我相信这些发行版已经内置了python-dev。

我相信python-dev已经安装好了。编译时可能未包含头文件路径

您可以通过以下方式搜索Python.h:

find| grep Python.h

如果无法在虚拟环境中找到该文件,则应使用如下简单命令安装该文件:

pip安装python-dev(或python2/3.x-dev)

获得路径后,您需要通过添加该路径来编译文件,例如,如果您正在使用conda:

gcc-I/home//anaconda3/envs//include/python3.7m/

如果您使用的是make实用程序,还可以通过使用导出为在C_INCLUDE_path(或CPP_INCLUDE_path,如果使用C++)中设置路径:


导出C\u INCLUDE\u PATH=/home//anaconda3/envs//INCLUDE/python3.7m/

@降档不起作用。。未找到python-dev可执行文件。@降档python-dev不是可执行文件,而是一组
*.h
标题。@Subomi.js python的哪个版本?对于python3,您需要
python3-dev
@Subomi如何
apt-get-install-python3-dev
向虚拟环境添加头文件?我面临着一个类似的问题,我需要一个虚拟环境
python3-dev
。请让我知道你是否能够解决这个问题,以及如何解决。谢谢。@saharudra嗨,一旦你激活了你的虚拟电视。它会更改您的路径变量,因此当您获取intsall python3 dev时,您正在将其安装到python3编译器可以定位头的正确位置。
apt get install build essential libssl dev libffi dev
(来自链接文章)解决了此问题,但它降级了GCC版本,带来了另一个问题。