win64位安裝python-mysqldb1.2.5


在其他版本的mysqldb里面時間查詢有問題
最后確定還是在 1.2.5 版本下來解決,需要解決的問題就是這個:
“Cannot open include file: 'config-win.h': No such file or directory” while installing mysql-python

上面是在 1.2.4 版本上的,后來在 1.2.5 上面應該是解決的。但實際上,1.2.5 在Windows 64 位環境下還是有問題的,原因見后面的說明。

安裝步驟如下:
1.安裝 Microsoft Visual C++ Compiler Package for Python 2.7
下載鏈接

2.安裝 MySQL Connector C 6.0.2
下載鏈接

3.下載 MySQL-python 1.2.5 源碼包
下載鏈接

4.解壓源碼包后,修改 site.cfg 文件。
實際上,如果你是在32 位系統上部署,那么通過pip install 安裝MySQL-python 1.2.5 只需進行上面的依賴包安裝即可。
但在 64 位環境中,就會提示“Cannot open include file: 'config-win.h'” 的錯誤。
原因就是 site.cfg 中寫的 MySQL Connector C 為32 位版本。

原來的 site.cfg 文件內容如下:

引用
# http://stackoverflow.com/questions/1972259/mysql-python-install-problem-using-virtualenv-windows-pip
# Windows connector libs for MySQL. You need a 32-bit connector for your 32-bit Python build.
connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2

修改為:

引用
connector = C:\Program Files\MySQL\MySQL Connector C 6.0.2


5.運行 python setup.py install 即可安裝完成。(摘取自http://www.linuxfly.org/windows_install_mysql_python_library/)

我在編譯過程中遇到以下問題:

1)問題: _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

原因:原因是安裝MySQL的時候沒有安裝C語言庫。

解決:重新運行MySQL的安裝程序,選擇Modify,把“C Include Files / Lib Files”勾選上,並安裝。

2)問題: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

原因:MySQL for python 1.2.3仍然是在尋找MySQL5.0的版本

解決:1、打開目錄下site.cfg文件,修改最后一行為“registry_key = SOFTWARE/MySQL AB/MySQL Server 5.1”
2、打開setup_windows.py文件,修改第七行為“serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE/MySQL AB/MySQL Server 5.1')”

3)問題: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

原因:路徑發生變化?

解決:打開“你的PYTHON安裝目錄/Lib/distutils/msvc9compiler.py”文件,找到“ld_args.append(’/MANIFESTFILE:’ + temp_manifest)”這行代碼,將其改為“ld_args.append(’/MANIFEST’)”

(4)當編譯完成以后,就可以輸入setup.py install了,現在終於大功告成了!

可以在DOS環境下輸入以下命令進行測試

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
>>>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM