使用 pip 安装软件包时缺少头文件
Posted
技术标签:
【中文标题】使用 pip 安装软件包时缺少头文件【英文标题】:Missing header files while installing packages using pip 【发布时间】:2015-02-19 14:39:16 【问题描述】:我试图让 mysql 与 django 一起工作。使用 pip 在 virtualenv 中安装所需的绑定会产生错误。
pip install MySQL-python
软件包已下载,但我收到以下错误消息,指出缺少头文件 my_config.h。
(django)[jmathews@localhost pollsys]$ pip install MySQL-python
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
Running setup.py (path:/home/jmathews/.virtualenvs/django/build/MySQL-python/setup.py) egg_info for package MySQL-python
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1
_mysql.c:44:23: fatal error: my_config.h: No such file or directory
#include "my_config.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /home/jmathews/.virtualenvs/django/bin/python -c "import setuptools, tokenize;__file__='/home/jmathews/.virtualenvs/django/build/MySQL-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Qa0mhq-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/jmathews/.virtualenvs/django/include/site/python2.7:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
creating build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1
_mysql.c:44:23: fatal error: my_config.h: No such file or directory
#include "my_config.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /home/jmathews/.virtualenvs/django/bin/python -c "import setuptools, tokenize;__file__='/home/jmathews/.virtualenvs/django/build/MySQL-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Qa0mhq-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/jmathews/.virtualenvs/django/include/site/python2.7 failed with error code 1 in /home/jmathews/.virtualenvs/django/build/MySQL-python
Storing debug log for failure in /home/jmathews/.pip/pip.log
以下软件包已安装和更新。
yum install -y gcc gcc-c++ libxml2-devel libxslt-devel
我也跑了
yum groupinstall "Development Tools" "Development Libraries"
问题仍然存在。是包有问题还是缺少任何依赖项?
【问题讨论】:
yum install mysql-devel
是的。它解决了这个问题。谢谢。
【参考方案1】:
你需要安装mysql库的头文件。
我不知道你的发行版,在 Ubuntu 上,包名是 libmysqlclient-dev
。
顺便说一句,如果开始一个新项目,我会推荐 PostgreSQL 而不是 MySQL,因为对 MySQL 的支持充其量是不确定的。
编辑:原来事情发生了变化,现在有bindings for Python 3
【讨论】:
是的,安装 yum 对应的 mysql-devel 解决了这个问题。我正在运行 MySQL,因为我的项目涉及许多读取操作和 PostgreSQL,我了解到读取操作较慢。【参考方案2】:yum info mysql-devel
如果没有安装,请安装
yum install mysql-devel
现在试试
sudo pip install mysql-python
【讨论】:
【参考方案3】:安装 mysql-dev 也解决了我的问题。非常感谢!
【讨论】:
【参考方案4】:yum install mysql-devel
然后
pip install MySQL-python
【讨论】:
以上是关于使用 pip 安装软件包时缺少头文件的主要内容,如果未能解决你的问题,请参考以下文章
ImportError:尝试安装软件包时没有名为 pip 的模块
virtualbox linux客户机中安装增强功能包缺少kernel头文件问题解决