Python MySQLdb Installation Problems and Solutions in Windows, pythonmysqldb

Source: Internet
Author: User

Python MySQLdb Installation Problems and Solutions in Windows, pythonmysqldb

Title: Because of work requirements, setting up the MySQL + Python + MySQLdb environment on CentOS, I am used to the operating habits of Windows systems, and I am not very familiar with character-only OS for the time being, we hope to build a similar environment on Windows for development. The following describes how to compile MySQLdb in Windows. I recently found a MySQLdb Windows installation package on the internet, it will be more convenient to use, address: http://www.codegood.com/archives/4

Or

Mysql-connector-python is a dedicated python driver provided by the MySQL official website. It is easy to use. There are many program instances in the file for your reference.

The process of manually compiling MySQLdb is as follows:

The following lists the software used above:

MySQL-http://www.mysql.com/<personal MySQL version: mysql-essential-5.1.53-win32.msi, maybe you have a new version when downloading.>

Python-http://www.python.org/<Python version for personal use: python-2.6.6.msi>

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

 

1. Install MySQL, select Custom, and check "C Include Files/Lib Files". If Typical is used, the problem may occur (1 ), the subsequent configurations are basically the default options, except for the additional check box "add to system PATH" (Include Bin Directory in Windows PATH. If you are not very clear about installing MySQL, you can search from the Internet, related articles a lot, as follows: http://rangyang163.blog.163.com/blog/static/37743758200881203744469/

2. Install Python, which is basically the default option, but slightly changed the installation path. The default installation path of Python is "C:/Python26", which is changed to "C:/Program Files/Python26"

3. You must install setuptools before installing MySQLdb. Otherwise, a compilation error may occur.

 

Setuptools-http://pypi.python.org/pypi/setuptools <drag the scroll bar down, and soon you will see a string that I personally use: setuptools-0.6c11.win32-py2.6.exe, Which is because the Python version I use is 2.66>

Install this tool by default...

 

Now, we can start to install mysqldb. the tar.gz package we downloaded is the source code package, and there is no installation program in it. We need to compile the package before installing it. <In fact, you only need to look at README to understand.>

(1)extract mysql-python-1.2.3.tar.gz to the current directory, a MySQL-python-1.2.3 folder appears;

(2) WIN + R, open the run dialog box, Enter cmd, open the MS-DOS, enter the folder decompressed above; (the premise is that you have to understand what cd is the command :-)....)

(3) Enter setup. py build to start compilation... <additionally, the C compiler is required for MySQLdb compilation. If MSVC is already installed, 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. However, you only need to install the appropriate compiler and configure the environment variables.>

I encountered the following problems during compilation:

1) Problem: _ mysql. c (34): fatal error C1083: Cannot open include file: 'config-win. H': No such file or directory
Error: command '"C:/Program Files/Microsoft Visual Studio 9.0/VC/BIN/cl.exe" 'failed' with exit status 2

Cause: the C language library is not installed when MySQL is installed.

Solution: run the MySQL installation program again, select Modify, select "C Include Files/Lib Files", and install it.

2) Problem: 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

Cause: MySQL for python 1.2.3 is still searching for MySQL

Solution: 1. Open the site. cfg file in the directory and change the last line to "registry_key = SOFTWARE/MySQL AB/MySQL Server 5.1"
2. Open the setup_windows.py file and modify the seventh behavior "serverKey = _ winreg. OpenKey (_ winreg. HKEY_LOCAL_MACHINE, 'Software/MySQL AB/MySQL Server 100 ')"

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

Cause: the path changes?

Solution: Open "Your PYTHON installation directory/Lib/distutils/msvc9compiler. in the "py" file, find the code "ld_args.append ('/MANIFESTFILE:' + temp_manifest)" and change it to "ld_args.append ('/MANIFEST ')"

(4) After compilation, enter setup. py install!

You can enter the following command in the DOS environment for testing:

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

This indicates that MySQLdb has been successfully installed! Next, you can learn Python + MySQLdb + MySQL. Have a good time!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.