问题描述
Linux下使用python开发,需要uwsgi模块时,常常会出现pip install 失败的情况,就像下图这样。是什么原因造成的呢?因为缺少一个python-devel包,所以只需要下载安装这个包就可以解决了。但是要特别注意python版本要与之对应的问题。
[root@VM_0_13_centos ~]# pip install uwsgi
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Collecting uwsgi
Downloading http://mirrors.tencentyun.com/pypi/packages/98/b2/19b34b20662d111f7d2f926cdf10e13381761dd7dbd10666b9076cbdcd22/uwsgi-2.0.17.tar.gz (798kB)
100% |████████████████████████████████| 798kB 2.6MB/s
Installing collected packages: uwsgi
Running setup.py install for uwsgi ... error
******省略******
[gcc -pthread] core/config_py.o
*** uWSGI compiling embedded plugins ***
[gcc -pthread] plugins/python/python_plugin.o
In file included from plugins/python/python_plugin.c:1:0:
plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
----------------------------------------
Command "/usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-e385dqxe/uwsgi/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-azcl8hbu/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-e385dqxe/uwsgi/
解决办法
从yum源上下载安装对应python版本的python-devel,如果不清楚的话先用 python --version 命令查看python版本,然后yum search python3,Tab键搜索出来下载。
[root@VM_0_13_centos ~]# yum install python36u-devel
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration*
******省略******
Installed:
python36u-devel.x86_64 0:3.6.5-1.ius.centos7
Complete!
Python-dev是个啥?
linux发行版通常会把类库的头文件和相关的pkg-config分拆成一个单独的xxx-dev(el)包.以下情况需要python-dev包:
- 安装一个源外的python类库, 而这个类库内含需要编译的调用python api的c/c++文件;
- 自己写的一个程序编译需要链接libpythonXX.(a|so)
(不含使用ctypes/ffi或者裸dlsym方式直接调用libpython.so)
其他正常使用python或者通过安装源内的python类库的不需要python-dev.