无法在Windows上安装mysqlclient Python软件包 [英] Unable to install mysqlclient Python package on Windows

查看:88
本文介绍了无法在Windows上安装mysqlclient Python软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装mysqlclient Python软件包( https://pypi.python.org /pypi/mysqlclient )导入Windows 7(在本地PC上和Appveyor CI上)的虚拟Python 2.7环境中,而无法完成.

I am trying to install the mysqlclient Python package (https://pypi.python.org/pypi/mysqlclient) into a virtual Python 2.7 environment on Windows 7 (on a local PC, and on the Appveyor CI) and cannot get it done.

我正在用Win 7描述本地PC的问题,但在Appveyor上发生的方式基本上相同.

I am describing the issues for the local PC with Win 7, but it happens basically the same way on Appveyor.

我启动时在我的virtualenv中打包:

Packages in my virtualenv when I start:

pip (9.0.1)
setuptools (36.6.0)
wheel (0.30.0)

pip install mysqlclient最初说:

. . .
running build_ext
building '_mysql' extension
error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27

显然,Python 2.7需要VC9.安装后,pip install mysqlclient会更进一步,但是会丢失包含文件:

Apparently, Python 2.7 requires VC9. After installing it, pip install mysqlclient gets a little further, but misses include files:

. . .
building '_mysql' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -IC:\Python27\include -IC:\Users\Andi\virtualenvs\mysqlclient\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.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)\\Common Files\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2

为了获取头文件,我从 https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.10-winx64.msi .诚然,这只是第二个最新版本,但是我需要从命令行将其安装在Appveyor上,并且没有找到如何以无人值守的方式下载最新版本.

In order to get the header files, I installed the "MySQL Connector/C 6.1.10" from https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.10-winx64.msi. This is admittedly only the second latest version, but I need to install it on Appveyor from the command line, and did not find out how to download the latest version in an unattended manner.

此外,使用MSI安装程序将软件包安装在C:\Program Files\MySQL\MySQL Connector C 6.1中,但是pip install中的构建步骤希望将其安装在C:\Program Files (x86)\MySQL\MySQL Connector C 6.1中,因此我将其软链接:

Also, using the MSI installer installs the package in C:\Program Files\MySQL\MySQL Connector C 6.1 but the build step in pip install expects it in C:\Program Files (x86)\MySQL\MySQL Connector C 6.1, so I softlinked it:

mklink /D "C:\Program Files (x86)\MySQL\MySQL Connector C 6.1" "C:\Program Files\MySQL\MySQL Connector C 6.1"

在该版本的MySQL Connector/C中查看文件时,它只有lib/vs12和lib/vs14目录:

When looking at the files in that version of the MySQL Connector/C, it has only lib/vs12 and lib/vs14 directories:

lib/vs12/mysqlclient.lib
lib/vs14/mysqlclient.lib

按预期,pip install mysqlclient现在超出了编译范围,但是在链接时失败:

As expected, pip install mysqlclient now gets beyond the compiles, but fails when linking:

. . .
running build_ext
building '_mysql' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -IC:\Python27\include -IC:\Users\Andi\virtualenvs\mysqlclient\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.7\Release\_mysql.obj /Zl
_mysql.c
_mysql.c(242) : .... several warnings ...
C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO "/LIBPATH:C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib\vs9" /LIBPATH:C:\Python27\Libs /LIBPATH:C:\Users\Andi\virtualenvs\mysqlclient\libs /LIBPATH:C:\Users\Andi\virtualenvs\mysqlclient\PCbuild\amd64 /LIBPATH:C:\Users\Andi\virtualenvs\mysqlclient\PC\VS9.0\amd64 kernel32.lib advapi32.lib wsock32.lib mysqlclient.lib /EXPORT:init_mysql build\temp.win-amd64-2.7\Release\_mysql.obj /OUT:build\lib.win-amd64-2.7\_mysql.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\_mysql.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\_mysql.pyd.manifest /MANIFEST
LINK : fatal error LNK1181: cannot open input file 'mysqlclient.lib'
error: command 'C:\\Program Files (x86)\\Common Files\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\link.exe' failed with exit status 1181

我没有找到仍然可以下载并且与VC9兼容的"MySQL Connector/C"软件包版本.在此vc9版本的vs12或vs14目录中使用mysqlclient.lib文件会导致无法解析的符号.

I did not find a version of the "MySQL Connector/C" package that can still be downloaded and that works with VC9. Using the mysqlclient.lib files in the vs12 or vs14 directories in this vc9 build results in unresolved symbols.

我的问题是:

  • 为了在Windows 7上成功pip install mysqlclient获得正确的头文件(例如mysql.h)和库(例如mysqlclient.lib),我需要使用哪些软件包?
  • 通常,在Windows 7上成功pip install mysqlclient的前提是什么?
  • What package(s) do I need to use in order to get the right header files (e.g. mysql.h) and libraries (e.g. mysqlclient.lib) for a successful pip install mysqlclient on Windows 7?
  • More generally, what are the prerequisites for a successful pip install mysqlclient on Windows 7?

推荐答案

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

选择与您的python版本匹配的版本,例如mysqlclient‑1.4.2‑cp37‑cp37m‑win_amd64.whl,然后:

choose the version matching your python version, example mysqlclient‑1.4.2‑cp37‑cp37m‑win_amd64.whl, and then:

pip install wheel

pip install mysqlclient‑1.4.2‑cp37‑cp37m‑win_amd64.whl

这篇关于无法在Windows上安装mysqlclient Python软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆