Windows Python2.7 mysqldb 安装错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32215285/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:14:06  来源:igfitidea点击:

Windows Python2.7 mysqldb installation error

windowspython-2.7installmysql-python

提问by altoids

I'm trying to install mysqldb for Python. I'm running "pip install mysql-python" and I keep getting this error:

我正在尝试为 Python 安装 mysqldb。我正在运行“pip install mysql-python”,但不断收到此错误:

running build_ext
building '_mysql' extension
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,'fi nal',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mysql.c /Fobui ld\temp.win32-2.7\Release_mysql.obj /Zl _mysql.c
_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe' failed with exit status 2

运行 build_ext
构建 '_mysql' 扩展
创建 build\temp.win32-2.7
创建 build\temp.win32-2.7\Release
C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\ cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86 )\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mysql.c /Fobui ld\temp.win32-2.7\Release_mysql.obj /Zl _mysql.c
_mysql .c(42):致命错误 C1083:无法打开包含文件:'config-win.h':没有这样的文件或目录
错误:命令 'C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python \9.0\VC\Bin\cl.exe' 失败,退出状态为 2

----------------------------------------
Failed building wheel for mysql-python
Failed to build mysql-python
Installing collected packages: mysql-python
Running setup.py install for mysql-python
Complete output from command c:\python27\python.exe -c "import setuptools, tokenize;file='c:\users\scott~1.sco\appdata\local\temp\pip-bu ild-nja4gr\mysql-python\setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install - -record c:\users\scott~1.sco\appdata\local\temp\pip-5htk1y-record\install-record.txt --single-version-externally-managed --compile: running install
running build
running build_py
copying MySQLdb\release.py -> build\lib.win32-2.7\MySQLdb
running build_ext
building '_mysql' extension
C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,' final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mysql.c /Fob uild\temp.win32-2.7\Release_mysql.obj /Zl _mysql.c
_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe' failed with exit status 2

------------------------------------------------
mysql-python 的构建轮
失败 构建失败mysql-python
安装收集的包:mysql-python
为mysql-python运行 setup.py install
命令的完整输出 c:\python27\python.exe -c "import setuptools, tokenize; file='c:\users\scott~1 .sco\appdata\local\temp\pip-build-nja4gr\mysql-python\setup.py';exec(compile(getattr(tokenize, 'open', open)( file).read().replace(' \r\n', '\n'), file, 'exec'))" install --record c:\users\scott~1.sco\appdata\local\temp\pip-5htk1y-record\install-record .txt --single-version-externally-managed --compile:运行安装
运行构建
运行build_py
复制 MySQLdb\release.py -> build\lib.win32-2.7\MySQLdb
running build_ext
building '_mysql' extension
C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl .exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\ MySQL\MySQL 连接器 C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mysql.c /Fob uild\temp.win32-2.7\Release_mysql.obj /Zl _mysql.c
_mysql.c (42):致命错误 C1083:无法打开包含文件:'config-win.h':没有这样的文件或目录
错误:命令 'C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0 \VC\Bin\cl.exe' 失败,退出状态为 2

----------------------------------------

Command "c:\python27\python.exe -c "import setuptools, tokenize;file='c:\users\scott~1.sco\appdata\local\temp\pip-build-nja4gr\mysql-python \setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record c:\users\scott~1 .sco\appdata\local\temp\pip-5htk1y-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\scott ~1.sco\appdata\local\temp\pip-build-nja4gr\mysql-python

命令“c:\python27\python.exe -c”导入设置工具,标记化;file='c:\users\scott~1.sco\appdata\local\temp\pip-build-nja4gr\mysql-python \setup.py';exec(compile(getattr(tokenize, 'open', open)( file).read().replace('\r\n', '\n'), file, 'exec'))" install --record c:\users\scott~1 .sco\appdata\local\temp \pip-5htk1y-record\install-record.txt --single-version-externally-managed --compile" 失败,错误代码 1 在 c:\users\scott ~1.sco\appdata\local\temp\pip-构建-nja4gr\mysql-python

Can anyone tell me whats the problem?

谁能告诉我是什么问题?

回答by Jayesh Vaghasiya

Download the pre-compiled whl file for mysql-pythonfrom from Christophe Gohlke's Library of pre-compiled python packages for windows from the below location.

mysql-python从以下位置从 Christophe Gohlke 的 Windows 预编译 python 包库下载预编译的 whl 文件。

https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

Now got to directory where you downloaded that file and open command prompt there.

现在到达下载该文件的目录并在那里打开命令提示符。

Now run below command pip install xxx.whl

现在运行下面的命令 pip install xxx.whl

Best Luck !!

好运 !!

回答by Javed

You can try...

你可以试试...

   pip install mysqlclient==1.3.4

It worked for me.

它对我有用。

If the above command doesn't work try this...

如果上面的命令不起作用试试这个...

 pip install --only-binary :all: mysqlclient

both worked for me.

两者都对我来说有效。

回答by PaniniGelato

I got a same error.

我遇到了同样的错误。

I solved it by install mysql-connector

我通过安装mysql-connector解决了它

回答by Sanju

You are missing Visual Studio C++ from your system or the correct environment for VS is not set properly based on the error in your question: "error: command 'C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe' failed with exit status 2"

您的系统中缺少 Visual Studio C++ 或 VS 的正确环境未根据您问题中的错误正确设置:“错误:命令 'C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python \9.0\VC\Bin\cl.exe' 失败,退出状态为 2"

Please check if you have C++ compiler installed at "C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe". If you do not have this installed it is available from Microsoft here: python27 Compiler

请检查您是否在“C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe”中安装了 C++ 编译器。如果你没有安装它,它可以从微软这里获得:python27 Compiler

If you have VS installed try running the pip install from visual studio command prompt ,which generally would have all the environment created or try to run vcvarsall.bat from "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\" folder

如果您安装了 VS,请尝试从 Visual Studio 命令提示符运行 pip install,这通常会创建所有环境或尝试从“C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin”运行 vcvarsall.bat \“ 文件夹

回答by zio

You can get a pre-compiled version from Christophe Gohlke's Library of pre-compiled python packages for windows. Specifically, you can find the MySQL_python package here

您可以从Christophe Gohlke 的 Windows 预编译 python 包库中获取预编译版本。具体来说,你可以在这里找到MySQL_python 包

Other alternatives would be to use a python distribution that comes with many packages pre-compiled and available for easy installation. Two examples are:

其他替代方法是使用 python 发行版,该发行版带有许多预编译的软件包,可用于轻松安装。两个例子是:

回答by Ashwin J Chhetri

Simply go to the site:

只需访问该网站:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

and download mysqlclient wheel file according to your python version and operating system bit specification, then install the downloaded file with typing

并根据您的python版本和操作系统位规范下载mysqlclient轮文件,然后键入安装下载的文件

pip install downloaded_whl_file_name

Finally install mysqldb with command:

最后用命令安装mysqldb:

pip install flask-mysqldb

回答by Max Segal

In my case I had to install mysql-connector with the same bitness as my python. So althoughI run 64bit windows 10, I have 32bit python 2.7 installed so I had to install 32bitmysql-connector from hereto overcome the error.

就我而言,我必须安装与我的 python 具有相同位数的 mysql-connector。因此,尽管我运行 64 位 Windows 10,但我安装了 32 位 python 2.7,因此我必须从此处安装32 位mysql-connector 以克服该错误。

回答by Alex Nina

The following action, mentioned above by zio, has solved my problem:

zio上面提到的以下操作解决了我的问题:

You can get a pre-compiled version from Christophe Gohlke's Library of pre-compiled python packages for windows. Specifically, you can find the MySQL_python package here. After get the file, install it using pip install.

您可以从 Christophe Gohlke 的 Windows 预编译 python 包库中获取预编译版本。具体来说,您可以在此处找到MySQL_python 包。获取文件后,使用 pip install 安装它。