摘要:环境下安装包经常会有各种环境方面的问题及报错。所以此次报错的原因就出来了,缺少了这个头文件。所以其核心原因在于环境的依赖库中不存在相关的文件。其它在上有网友提供了一个较为省事儿的解决办法,直接下载现成的文件到本地进行安装资源地址。
Windows 环境下安装python包经常会有各种环境方面的问题及报错。 最近在python36/37下升级安装mysqlclient包时产生了下面的错误,不论是百度还是Stack Overflow上查找都没有真正的解决方案,于是写文章与大家一起分享下这类报错的解决方法。
报错信息:Building wheels for collected packages: mysqlclient Running setup.py bdist_wheel for mysqlclient ... error Complete output from command "d:program filespythonpython36python.exe" -u -c "import setuptools, tokenize;__file__="C:Userszdl25AppDataLocalTemppip-install-83rodr64mysqlclientsetup.py";f=getattr(tokenize, "open", open)(__file__);code=f.read().replace(" ", " ");f.close();exec(compile(code, __file__, "exec"))" bdist_wheel -d C:Userszdl25AppDataLocalTemppip-wheel-nlo8hs6x --python-tag cp36: running bdist_wheel running build running build_py creating build creating buildlib.win-amd64-3.6 copying _mysql_exceptions.py -> buildlib.win-amd64-3.6 creating buildlib.win-amd64-3.6MySQLdb copying MySQLdb\__init__.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdbcompat.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdbconnections.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdbconverters.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdbcursors.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdb elease.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdb imes.py -> buildlib.win-amd64-3.6MySQLdb creating buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstants\__init__.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsCLIENT.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsCR.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsER.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsFIELD_TYPE.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsFLAG.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsREFRESH.py -> buildlib.win-amd64-3.6MySQLdbconstants running build_ext building "_mysql" extension creating build emp.win-amd64-3.6 creating build emp.win-amd64-3.6Release C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.15.26726inHostX86x64cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,13,"final",0) -D__version__=1.3.13 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1include" "-Id:program filespythonpython36include" "-Id:program filespythonpython36include" "-IC:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.15.26726include" "-IC:Program Files (x86)Windows Kits10include10.0.10240.0ucrt" "-IC:Program Files (x86)Windows Kits8.1includeshared" "-IC:Program Files (x86)Windows Kits8.1includeum" "-IC:Program Files (x86)Windows Kits8.1includewinrt" "-IC:Program Files (x86)Windows Kits8.1includecppwinrt" /Tc_mysql.c /Fobuild emp.win-amd64-3.6Release\_mysql.obj /Zl _mysql.c _mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory error: command "C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.15.26726inHostX86x64cl.exe" failed with exit status 2 ---------------------------------------- Failed building wheel for mysqlclient Running setup.py clean for mysqlclient Failed to build mysqlclient Installing collected packages: mysqlclient Found existing installation: mysqlclient 1.3.12 Uninstalling mysqlclient-1.3.12: Successfully uninstalled mysqlclient-1.3.12 Running setup.py install for mysqlclient ... error Complete output from command "d:program filespythonpython36python.exe" -u -c "import setuptools, tokenize;__file__="C:Userszdl25AppDataLocalTemppip-install-83rodr64mysqlclientsetup.py";f=getattr(tokenize, "open", open)(__file__);code=f.read().replace(" ", " ");f.close();exec(compile(code, __file__, "exec"))" install --record C:Userszdl25AppDataLocalTemppip-record-f544g5zoinstall-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating buildlib.win-amd64-3.6 copying _mysql_exceptions.py -> buildlib.win-amd64-3.6 creating buildlib.win-amd64-3.6MySQLdb copying MySQLdb\__init__.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdbcompat.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdbconnections.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdbconverters.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdbcursors.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdb elease.py -> buildlib.win-amd64-3.6MySQLdb copying MySQLdb imes.py -> buildlib.win-amd64-3.6MySQLdb creating buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstants\__init__.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsCLIENT.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsCR.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsER.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsFIELD_TYPE.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsFLAG.py -> buildlib.win-amd64-3.6MySQLdbconstants copying MySQLdbconstantsREFRESH.py -> buildlib.win-amd64-3.6MySQLdbconstants running build_ext building "_mysql" extension creating build emp.win-amd64-3.6 creating build emp.win-amd64-3.6Release C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.15.26726inHostX86x64cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,13,"final",0) -D__version__=1.3.13 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1include" "-Id:program filespythonpython36include" "-Id:program filespythonpython36include" "-IC:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.15.26726include" "-IC:Program Files (x86)Windows Kits10include10.0.10240.0ucrt" "-IC:Program Files (x86)Windows Kits8.1includeshared" "-IC:Program Files (x86)Windows Kits8.1includeum" "-IC:Program Files (x86)Windows Kits8.1includewinrt" "-IC:Program Files (x86)Windows Kits8.1includecppwinrt" /Tc_mysql.c /Fobuild emp.win-amd64-3.6Release\_mysql.obj /Zl _mysql.c _mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory error: command "C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.15.26726inHostX86x64cl.exe" failed with exit status 2 ---------------------------------------- Rolling back uninstall of mysqlclient Command ""d:program filespythonpython36python.exe" -u -c "import setuptools, tokenize;__file__="C:Userszdl25AppDataLocalTemppip-install-83rodr64mysqlclientsetup.py";f=getattr(tokenize, "open", open)(__file__);code=f.read().replace(" ", " ");f.close();exec(compile(code, __file__, "exec"))" install --record C:Userszdl25AppDataLocalTemppip-record-f544g5zoinstall-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:Userszdl25AppDataLocalTemppip-install-83rodr64mysqlclient原因排查
此类问题需要真正的会看且有耐心去看报错信息,根据报错去分析和思考问题出在哪个环节上,然后一步一步缩减范围,锁定问题原因。cl.exe" failed with exit status 2 基本上都是因为编译过程中缺少必要的依赖库文件所导致的。缺少哪个类库文件,上面的报错信息会有指出来—— _mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory。 所以此次报错的原因就出来了,缺少了 mysql.h 这个头文件。
当把mysql.h添加进类库后,还会报 [ binary_log_types.h, errmsg.h, my_command.h, my_list.h, mysql_com.h, mysql_time.h, mysql_version.h, mysqld_error.h, mysql/client_plugin.h, mysql/plugin_auth_common.h, mysql/udf_registration_types.h ]。
所以其核心原因在于环境的依赖库中不存在mysql相关的文件。去MySQL官方下载个MySQL-Server包[https://dev.mysql.com/downloa...],zip或者installer均可
,如果本机上已经有MySQL-Server也行,到图中MySQL-Server目录中include中拷贝图中选中的文件及文件夹到依赖库目录中去。
上面的报错信息我们从下往上倒推,在“mysql.h”: No such file or directory这行往上第二行,报错中的 -IC:Program Files (x86)MySQLMySQL Connector C 6.1include, 在每一个 -I 后面紧跟的就是系统会查找的库目录。只要其中任何一个路径下能找到报错中需要依赖的头文件就能让安装顺利进行下去。
虽然python的安装目录下的include文件夹也可以存放这些依赖文件,但如果你的系统中安装有多个不同的python版本,那么为了避免复制多分这些依赖文件,还是建议放到其它目录中,这样不同Python版本下安装都没有问题。
大功告成了?只差最后一步了。
以上的依赖库文件添加完之后,还会再依赖一个静态类库文件。这个文件在 MySQL-Server/lib 中。
# 只截取以下关键错误信息贴出 C:Program Files (x86)Microsoft Visual Studio 14.0VCBINx86_amd64link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:C:Program Files (x86)MySQLMySQL Connector C 6.1libvs14" "/LIBPATH:D:Program FilesPythonPython37libs" "/LIBPATH:D:Program FilesPythonPython37PCbuildamd64" "/LIBPATH:C:Program Files (x86)Microsoft Visual Studio 14.0VCLIBamd64" "/LIBPATH:C:Program Files (x86)Windows Kits10lib10.0.10240.0ucrtx64" "/LIBPATH:C:Program Files (x86)Windows Kits8.1libwinv6.3umx64" kernel32.lib advapi32.lib wsock32.lib mysqlclient.lib /EXPORT:PyInit__mysql build emp.win-amd64-3.7Release\_mysql.obj /OUT:buildlib.win-amd64-3.7\_mysql.cp37-win_amd64.pyd /IMPLIB:build emp.win-amd64-3.7Release\_mysql.cp37-win_amd64.lib /MANIFEST LINK : fatal error LNK1181: cannot open input file "mysqlclient.lib" D:Program FilesPythonPython37libdistutilsdist.py:274: UserWarning: Unknown distribution option: "long_description_content_type" warnings.warn(msg) error: command "C:Program Files (x86)Microsoft Visual Studio 14.0VCBINx86_amd64link.exe" failed with exit status 1181
根据以上报错,将 mysqlclient.lib 文件从MySQL-Server那里拷贝到任意一个 /LIBPATH即可!
OK.
虽然今天对于我们来说只是mysqlclient这个包的安装问题,但其实还有很多网友在搜索许多类似原因导致的包无法正常安装的问题,比如cudarray, pyltp, Scrapy等等,相信这篇文章一样可以帮助他们找到解决方案。
其它在Stack Overflow上有网友提供了一个较为省事儿的解决办法,直接下载现成的.whl文件到本地进行安装(资源地址:https://www.lfd.uci.edu/~gohl...)。
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/42541.html
摘要:本人年开发经验,现就职于电信,因工作需要学习,记录自己的学习记录。 本人java10年开发经验,现就职于电信,因工作需要学习python,记录自己的学习记录。后面也...
摘要:下安装出错注意用,从起,变更为安装的驱动是的但是毫不意外的出错了一般安装运行上面的神器命令都会出错,即使在下也是,直接上解决办法到下载二进制安装包网站打开大概是酱紫的通过搜索然后就酱紫了下载位版本然后运行安装然后稍等一下 windows下mysql-python安装出错 注意:python2.x用mysql-python,从Python3.x起,变更为mysqlclient windo...
摘要:中默认使用数据库,今天研究了下如何将它换成常见的数据库。由于项目用得,而没有支持的版本,如果使用版本时,时会报错。 Django中默认使用sqlite3数据库,今天研究了下如何将它换成常见的mysql数据库。 由于项目用得python3,而MySQLdb没有支持python3的版本,如果使用python3.x版本时,pip install MySQLdb时会报错。 后来通过谷歌发现...
阅读 2457·2021-11-19 09:40
阅读 3584·2021-11-17 17:08
阅读 3784·2021-09-10 10:50
阅读 2213·2019-08-27 10:56
阅读 1942·2019-08-27 10:55
阅读 2637·2019-08-26 12:14
阅读 994·2019-08-26 11:58
阅读 1493·2019-08-26 10:43