Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

mysql - Unable to install mysqlclient Python package on Windows

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.

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

Packages in my virtualenv when I start:

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

pip install mysqlclient initially says:

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

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

. . .
building '_mysql' extension
creating buildemp.win-amd64-2.7
creating buildemp.win-amd64-2.7Release
C:Program Files (x86)Common FilesMicrosoftVisual C++ for Python9.0VCBinamd64cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1include" -IC:Python27include -IC:UsersAndivirtualenvsmysqlclientPC /Tc_mysql.c /Fobuildemp.win-amd64-2.7Release\_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

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.

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

mklink /D "C:Program Files (x86)MySQLMySQL Connector C 6.1" "C:Program FilesMySQLMySQL Connector C 6.1"

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

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

. . .
running build_ext
building '_mysql' extension
creating buildemp.win-amd64-2.7
creating buildemp.win-amd64-2.7Release
C:Program Files (x86)Common FilesMicrosoftVisual C++ for Python9.0VCBinamd64cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1include" -IC:Python27include -IC:UsersAndivirtualenvsmysqlclientPC /Tc_mysql.c /Fobuildemp.win-amd64-2.7Release\_mysql.obj /Zl
_mysql.c
_mysql.c(242) : .... several warnings ...
C:Program Files (x86)Common FilesMicrosoftVisual C++ for Python9.0VCBinamd64link.exe /DLL /nologo /INCREMENTAL:NO "/LIBPATH:C:Program Files (x86)MySQLMySQL Connector C 6.1libvs9" /LIBPATH:C:Python27Libs /LIBPATH:C:UsersAndivirtualenvsmysqlclientlibs /LIBPATH:C:UsersAndivirtualenvsmysqlclientPCbuildamd64 /LIBPATH:C:UsersAndivirtualenvsmysqlclientPCVS9.0amd64 kernel32.lib advapi32.lib wsock32.lib mysqlclient.lib /EXPORT:init_mysql buildemp.win-amd64-2.7Release\_mysql.obj /OUT:buildlib.win-amd64-2.7\_mysql.pyd /IMPLIB:buildemp.win-amd64-2.7Release\_mysql.lib /MANIFESTFILE:buildemp.win-amd64-2.7Release\_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

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.

My questions are:

  • 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?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...