为 python 2.7 安装 MySQLdb 返回错误 [英] Installing MySQLdb for python 2.7 returns error
本文介绍了为 python 2.7 安装 MySQLdb 返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
pip install MySQL-python-1.2.4b4.tar.gz 在 Python 2.7 (ubuntu 18.04) 上返回此错误:
你能帮我吗?
<前># pip install MySQL-python-1.2.5.zip处理 ./MySQL-python-1.2.5.zip为收集的包构建轮子:MySQL-python为 MySQL-python 运行 setup.py bdist_wheel ... 错误命令/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-00mbCK-build/setup.py';f=getattr(tokeni ze, 'open', open) 的完整输出(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d/tmp/tmpePf4 ITpip-wheel---python-tag cp27:运行 bdist_wheel运行构建运行 build_py创建构建创建 build/lib.linux-x86_64-2.7复制 _mysql_exceptions.py -> build/lib.linux-x86_64-2.7创建 build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb创建 build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants运行 build_ext构建_mysql"扩展创建 build/temp.linux-x86_64-2.7x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -f debug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=.-fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_in fo=(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_mysql.c:44:10: 致命错误: my_config.h: 没有那个文件或目录#include "my_config.h"^~~~~~~~~~~~~编译终止.错误:命令x86_64-linux-gnu-gcc"失败,退出状态为 1---------------------------MySQL-python 的构建轮失败为 MySQL-python 运行 setup.py clean构建 MySQL-python 失败安装收集的包:MySQL-python为 MySQL-python 运行 setup.py install ... 错误命令/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-00mbCK-build/setup.py';f=getattr(toke nize, 'open', open) 的完整输出(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --记录/tmp/pip -vhjCMt-record/install-record.txt --single-version-externally-managed --compile:运行安装运行构建运行 build_py创建构建创建 build/lib.linux-x86_64-2.7复制 _mysql_exceptions.py -> build/lib.linux-x86_64-2.7创建 build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb复制 MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb创建 build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants复制 MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants运行 build_ext构建_mysql"扩展创建 build/temp.linux-x86_64-2.7x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=.-fstack-protector-strong -Wformat -Werror=format-security -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_mysql.c:44:10: 致命错误: my_config.h: 没有那个文件或目录#include "my_config.h"^~~~~~~~~~~~~编译终止.错误:命令x86_64-linux-gnu-gcc"失败,退出状态为 1---------------------------命令 "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-00mbCK-build/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-vhjCMt-record/install-r ecord.txt --single-version-externally-managed --compile" 失败,错误代码 1 在/tmp/pip-00mbCK-build/谢谢.
解决方案
如果你使用:
<块引用>pip install mysqlclient==1.4.6
相反,你会发现它有效.mariadb包改变了一些头文件的存储方式,MySQL-python pip包已经很多年没有更新了.
我遇到了同样的问题,切换对我有用.
pip install MySQL-python-1.2.4b4.tar.gz returns this error on Python 2.7 (ubuntu 18.04):
Can you help me?
# pip install MySQL-python-1.2.5.zip Processing ./MySQL-python-1.2.5.zip Building wheels for collected packages: MySQL-python Running setup.py bdist_wheel for MySQL-python ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-00mbCK-build/setup.py';f=getattr(tokeni ze, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpePf4 ITpip-wheel- --python-tag cp27: running bdist_wheel 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 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -f debug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_in fo=(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 _mysql.c:44:10: fatal error: my_config.h: No such file or directory #include "my_config.h" ^~~~~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Failed building wheel for MySQL-python Running setup.py clean for MySQL-python Failed to build MySQL-python Installing collected packages: MySQL-python Running setup.py install for MySQL-python ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-00mbCK-build/setup.py';f=getattr(toke nize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip -vhjCMt-record/install-record.txt --single-version-externally-managed --compile: 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 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -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 _mysql.c:44:10: fatal error: my_config.h: No such file or directory #include "my_config.h" ^~~~~~~~~~~~~ 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-00mbCK-build/setup.py';f=getattr(tokenize, 'open', open)(__fi le__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-vhjCMt-record/install-r ecord.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-00mbCK-build/
Thanks.
解决方案
If you use:
pip install mysqlclient==1.4.6
instead, then you'll find it works. The mariadb package has changed the way it stores some header files, and the MySQL-python pip package hasn't been updated for many years.
I had the same problem and switching worked for me.
这篇关于为 python 2.7 安装 MySQLdb 返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文