import _mysql----ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。
背景: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 "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 19, in <module>
import _mysql
ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。
>>> exit()
解决方法:
打开网站找到mysql-python模块
选择第四个whl文件。
在文件位置打开cmd,运行pip install MySQL_python‑1.2.5‑cp27‑none‑win_amd64.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