摘要:環境下安裝包經常會有各種環境方面的問題及報錯。所以此次報錯的原因就出來了,缺少了這個頭文件。所以其核心原因在于環境的依賴庫中不存在相關的文件。其它在上有網友提供了一個較為省事兒的解決辦法,直接下載現成的文件到本地進行安裝資源地址。
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...)。
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/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時會報錯。 后來通過谷歌發現...
閱讀 2463·2021-11-19 09:40
閱讀 3589·2021-11-17 17:08
閱讀 3794·2021-09-10 10:50
閱讀 2220·2019-08-27 10:56
閱讀 1946·2019-08-27 10:55
閱讀 2643·2019-08-26 12:14
閱讀 997·2019-08-26 11:58
閱讀 1498·2019-08-26 10:43