mysql不是有效win32应用程序_import _mysql----ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。...

在运行Python 2.7.13 64位版本时,尝试导入MySQLdb模块时遇到ImportError,提示'%1 不是有效的 Win32 应用程序'。问题出在安装的mysql-python是32位版本,与64位Python不兼容。解决方案是卸载32位版本,从下载64位的whl文件并使用pip安装。成功安装后,可以正常导入MySQLdb。
摘要由CSDN通过智能技术生成

背景: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模块

3bce91dbc640a47d2f6779ca28ab3004.png

选择第四个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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值