Python 3.7,MySql-Python 的构建轮失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51117503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 3.7, Failed building wheel for MySql-Python
提问by ronan
I am new to python and I am trying django framework that involves some MySql and ran into this error when try to do pip install mysqlclient
and down the lines of cmd messages I got this.
我是 python 的新手,我正在尝试涉及一些 MySql 的 django 框架,并在尝试执行pip install mysqlclient
和沿着我得到的 cmd 消息行时遇到了这个错误。
Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command c:\users\ronanl~1\envs\py1\scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\RONANL~1\AppData\Local\Temp\pip-install-pkbqy3t3\mysqlclient\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\RONANL~1\AppData\Local\Temp\pip-record-moxwf7lu\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\ronanl~1\envs\py1\include\site\python3.7\mysqlclient:
running install
running build
running build_py
creating build
creating build\lib.win32-3.7
copying _mysql_exceptions.py -> build\lib.win32-3.7
creating build\lib.win32-3.7\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb
copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb
copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
creating build\lib.win32-3.7\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.7\MySQLdb\constants
running build_ext
building '_mysql' extension
creating build\temp.win32-3.7
creating build\temp.win32-3.7\Release
C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" "-Ic:\users\ronan lina\appdata\local\programs\python\python37-32\include" "-Ic:\users\ronan lina\appdata\local\programs\python\python37-32\include" "-IC:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\cppwinrt" /Tc_mysql.c /Fobuild\temp.win32-3.7\Release\_mysql.obj /Zl
_mysql.c
_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\cl.exe' failed with exit status 2
>
>
> Command "c:\users\ronanl~1\envs\py1\scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\RONANL~1\AppData\Local\Temp\pip-install-pkbqy3t3\mysqlclient\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\RONANL~1\AppData\Local\Temp\pip-record-moxwf7lu\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\ronanl~1\envs\py1\include\site\python3.7\mysqlclient" failed with error code 1 in C:\Users\RONANL~1\AppData\Local\Temp\pip-install-pkbqy3t3\mysqlclient\
anyone knows how to fix this ?
有谁知道如何解决这个问题?
回答by Junaid
I installed the following library on Ubuntuand after that, the issue got resolved.
我在Ubuntu上安装了以下库,之后问题就解决了。
sudo apt-get install libssl-dev
and then I was able to install mysqlclient using the following command
然后我可以使用以下命令安装 mysqlclient
pip install mysqlclient
回答by Bhavishya Prasad BfutureP
currently the mysql-connector for python 3.7 is not available in official wesite but u can fix this issue by installing wheel with specific windows and python version.
this solutionpip install (ex/dir)/mysqlclient-1.3.13-cp37-cp37m-win_amd64.whl
for win 64-bi and python 3.7
目前官方网站上没有用于 python 3.7 的 mysql-connector,但你可以通过安装具有特定 Windows 和 python 版本的轮子来解决这个问题。此解决方案pip install (ex/dir)/mysqlclient-1.3.13-cp37-cp37m-win_amd64.whl
适用于 win 64-bi 和 python 3.7
check the link below and download the specific wheel for your system. download and install the wheel for specific version by using "pip install (full path with file name in my case ex:-"pip install C:\Users\%user%\Downloads\mysqlclient-1.3.13-cp37-cp37m-win_amd64.whl")
检查下面的链接并为您的系统下载特定的轮子。 使用“pip install(在我的情况下为文件名的完整路径,例如:-”pip install C:\Users\%user%\Downloads\mysqlclient-1.3.13-cp37-cp37m-win_amd64 下载并安装特定版本的轮子.whl")
回答by PyMaster
You need to install the following dependencies before installing mysqlclient for python 3.7in your system.
在您的系统中为python 3.7安装 mysqlclient 之前,您需要安装以下依赖项。
sudo apt-get install python3.7-dev default-libmysqlclient-dev
sudo apt-get install python3.7-dev default-libmysqlclient-dev
I hope this will help you.
我希望这能帮到您。
回答by louis_guitton
As of 2019, here is how to run smoothly pip install mysqlclient
on MacOS:
截至 2019 年,以下是如何pip install mysqlclient
在 MacOS 上顺利运行:
brew info openssl
and follow the commands at the bottom
brew info openssl
并按照底部的命令
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
Other approaches:
其他方法:
brew install/upgrade/reinstall mysql
: did not fix the issue for me, but has the nice side effect to make sure your installation is clean.brew install mysql-connector-c
: to make that work you have to unlink mysql, which ruins your setup and it did not fix the issue for me.
brew install/upgrade/reinstall mysql
: 没有为我解决这个问题,但有一个很好的副作用来确保你的安装是干净的。brew install mysql-connector-c
:要完成这项工作,您必须取消与 mysql 的链接,这会破坏您的设置并且没有为我解决问题。
回答by István D?brentei
I installed it with the following command and works well now (on Mac):
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
我使用以下命令安装了它并且现在运行良好(在 Mac 上):
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
see connected answer: Error installing mysql-python: library not found for -lssl
请参阅连接的答案: 安装 mysql-python 时出错:找不到 -lssl 的库
回答by Nour Noby
You have to install "mysqlclient-1.4.1-cp37-cp37m-win32.whl" (32bit) file
你必须安装“mysqlclient-1.4.1-cp37-cp37m-win32.whl”(32位)文件
- Download 32bitfile from https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
if your file is in Downloadsfolder write the command in your cmd
i.
cd C:\Users\Nour Noby\Downloads
["Nour Noby" should be changed ]ii.
pip install mysqlclient-1.4.1-cp37-cp37m-win32.whl
["mysqlclient-1.4.1-cp37-cp37m-win32.whl" should be replaced with your downloaded filename].
- 从https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient下载32 位文件
如果您的文件在下载文件夹中,请在您的cmd 中写入命令
一世。
cd C:\Users\Nour Noby\Downloads
[“Nour Noby”应该改变]ii.
pip install mysqlclient-1.4.1-cp37-cp37m-win32.whl
[“mysqlclient-1.4.1-cp37-cp37m-win32.whl”应替换为您下载的文件名]。
回答by Mehdi
ensuring you have had done the needful with python...
确保你已经用 python 完成了必要的工作......
and installing on the global level... (not virtual environment)
并在全球范围内安装......(不是虚拟环境)
sudo apt-get install mysql-server
pip install --upgrade setuptools
sudo apt-get install mysql-server
pip install --upgrade setuptools
I had come across the same problem, because I installed default Python2.7.15, and python3 would break even after doing the needful for Python (being python2)
我遇到了同样的问题,因为我安装了默认的 Python2.7.15,python3 在为 Python 做了必要的事情后会收支平衡(作为 python2)
something that worked for me was (effectively the last one is what made it work, but i think they were equally required on my virtualenvironment with python3)
对我有用的东西是(实际上最后一个是让它起作用的,但我认为它们在我的虚拟环境中与 python3 一样需要)
sudo apt-get install libmysqlclient-dev
sudo apt-get install python3-pymysql
sudo apt-get install python3.6-dev
python3.7 in your case in the virtualenv
python3.7在你的情况下在virtualenv
I also had to go through..
我也得过..
回答by Shedrack
Try this first
先试试这个
sudo apt-get install python3.7-dev
Then
然后
pip install mysqlclient
回答by Archisman Pathak
In my case, I had the 32-bit version of Python installed, instead of the 64-bit one. Install 64-bit Python and it would work alright.
就我而言,我安装了 32 位版本的 Python,而不是 64 位版本。安装 64 位 Python,它会正常工作。
回答by avee chakraborty
use this command :
sudo apt-get install libssl-dev
使用这个命令:
sudo apt-get install libssl-dev