背景:python 2.7.13 64位,安装了mysql-phthon, import MySQLdb 提示 ImportError DLL load failed: %1 不是有效的 Win32 应用程序
C:\Users\dell>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 19, in
import _mysql
ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。
>>> exit()
解决方法:
操作系统win7,64位,查看安装的mysql-python包:MySQL-python-1.2.5.win32-py2.7.exe ,32位,版本不匹配,导致出错。重新安装64位安装包即可,
如何查看mysql-python 版本及位数,我不知道是否有别的方法,我是通过安装日志 MySQL-python-wininst.log 看到的,
...
Source: C:\Users\dell\Downloads\MySQL-python-1.2.5.win32-py2.7.exe
...
下载地址:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
打开网站找到mysql-python模块
选择第四个whl文件。
不出意外的话就会提示安装成功。
首先卸载安装的32位版本
C:\Users\dell>pip uninstall mysql-python
Uninstalling MySQL-python-1.2.5:
c:\python27\lib\site-packages\_mysql_exceptions.py
c:\python27\lib\site-packages\mysql_python-1.2.5-py2.7.egg-info
c:\python27\lib\site-packages\mysqldb
Proceed (y/n)? y
Successfully uninstalled MySQL-python-1.2.5
然后安装64位版本
C:\Users\dell>pip install "\Users\dell\Downloads\MySQL_python-1.2.5-cp27-none-win_amd64.whl"
Processing c:\users\dell\downloads\mysql_python-1.2.5-cp27-none-win_amd64.whl
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.5