Problems encountered and solutions to installing python MySQLdb under Windows

  • 2020-05-26 09:36:19
  • OfStack

Opening sentence: because of the work needs, I built an environment MySQL+Python+MySQLdb on CentOS. I am quite used to the operation of Windows system, but I am not used to the pure OS for the time being. Therefore, I hope to build a similar environment on Windows system for development. The following describes the process of compiling MySQLdb in an Windows environment. Complement 1: in a recent online search to a MySQLdb Windows installation package, will be more convenient to use 1, address: http: / / www codegood. com archives / 4

Or to https: / / www. ofstack. com softs / 73369 html download, of course, also can go to the https: / / dev mysql. com/downloads/connector/python/download

mysql-connector-python is a driver specially connected to python on MySQL's official website. It's easy to use. There are many examples in the file for reference.

The process of manually compiling MySQLdb is as follows:

Here is a list of download addresses for the above software:

MySQL - http://www.mysql.com/ < MySQL version for personal use: mysql-essential-5.1.53-win32.msi, you may have a new version when you download it. >

Python - http://www.python.org/ < Version Python for personal use: python-2.6.6.6.msi >

MySQLdb - http://sourceforge.net/projects/mysql-python/ < MySQLdb version for personal use: MySQL-python-1.2.3.tar.gz >

1. Install MySQL, select Custom, and check "C Include Files/Lib Files". If you use Typical, there will be a problem (1). If you install MySQL is not very clear, l can search on the Internet, many related articles, as follows: http: / / rangyang163 blog. 163. com/blog/static / 37743758200881203744469 /

2. Install Python, which is basically the default option, with the installation path slightly changed by 1. The default installation path for Python is "C:/Python26", which I am used to changing to "C:/Program Files/Python26".

3. You must install setuptools before installing MySQLdb, otherwise there will be compilation errors.

Setuptools - http://pypi.python.org/pypi/setuptools < Drag the scroll bar down, and you will soon see a list of download addresses. setuptools-0.6 c11.win32-py2.6.exe. This is because I am using version 2.66 of Python >

Install this tool by default...

Ok, you can officially start to install MySQLdb, we download the tar.gz is the source package, there is no installation procedures, need to compile first, then install. < Just look at README. >

(1) unzip MySQL-python-1.2.3.tar.gz into the current directory, and a folder MySQL-python-1.2.3 will appear;

(2) WIN+R, open the run dialog box, enter cmd, open MS-DOS, enter the folder unzipped above; (if you understand what cd is :-)...)

(3) enter setup.py build starts to compile... < One additional point is that you need the C compiler to compile MySQLdb, and if you have installed MSVC, you can compile it directly. If you need to specify a compiler, you can use the compiler switch. For example, compiler=mingw32 USES GCC as the compiler, but only if you install the appropriate compiler and configure the environment variables. >

I encountered the following problems during the compilation process:

1) question: _mysql.c (34) : fatal error C1083: Cannot include open include include file ': No such or directory
error: command '" C: / Program Files/Microsoft Visual Studio 9.0 / VC BIN/cl exe "' failed with exit status 2

Reason: the reason is that the C language library was not installed when MySQL was installed.

Solution: rerun the MySQL installer, select Modify, tick "C Include Files/Lib Files" and install.

2) questions: Traceback (most recent call last):
File "setup.py", line 15, in < module >
metadata, options = get_config()
File "C:/MySQL-python-1.2.3/setup_windows.py", line 7, in get_config
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key'])
WindowsError: [Error 2] The system cannot find the file specified

Reason: MySQL for python 1.2.3 is still looking for version MySQL 5.0

Solution: 1. Open the site.cfg file in the directory and modify the last 1 behavior "registry_key = SOFTWARE/MySQL AB/MySQL Server 5.1".
2. Open the setup_windows.py file and modify act 7 "serverKey = _winreg.OpenKey (_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE/MySQL AB/MySQL Server 5.1')"

3) question: build/temp. win32-2.7 / Release / _mysql pyd. manifest: general error c1010070: Failed to and parse the manifest The system cannot the the file specified
error: command 'mt.exe' failed with exit status 31

Reason: path change?

Solution: open "your PYTHON installation directory/Lib distutils/msvc9compiler py" file, find the "ld_args. append ('/MANIFESTFILE: + temp_manifest)" this line of code, it is changed to "ld_args. append ('/MANIFEST ')"

(4) when the compilation is complete, you can type setup.py install, and now you are done!

You can test it by entering the following command in the DOS environment:


C:/Users/Michael>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

This means that MySQLdb has been installed successfully! Now, you can learn Python+MySQLdb+MySQL. Have a nice day!


Related articles: