设置脚本退出,错误:找不到 vcvarsall.bat
我在运行我的脚本时遇到了以下错误
Traceback (most recent call last):
File "mysql.py", line 2, in <module>
import MySQLdb
ImportError: No module named MySQLdb
我尝试按照“没有名为MySQLdb的模块”的建议安装mysql-python,但遇到了以下错误,有人能建议我怎么解决这个错误吗?
C:\Dropbox\scripts>easy_install mysql-python
Searching for mysql-python
Reading http://pypi.python.org/simple/mysql-python/
Best match: MySQL-python 1.2.5
Downloading https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
Processing MySQL-python-1.2.5.zip
Running MySQL-python-1.2.5\setup.py -q bdist_egg --dist-dir c:\users\gnakkala\appdata\local\temp\easy_install-kowc5r\MySQL-python-1.2.5\egg-dist-tmp-1gslvq
error: Setup script exited with error: Unable to find vcvarsall.bat
2 个回答
0
1 安装 wheel
pip install wheel
2 从 http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 下载 .whl 文件
按 Ctrl+F,搜索 mysql,你可以找到:
MySQL-python, a Python database API 2.0 interface for the MySQL database
Mysqlclient is a Python 3 compatible fork of MySQL-python.
MySQL_python-1.2.5-cp27-none-win32.whl
MySQL_python-1.2.5-cp27-none-win_amd64.whl
Mysqlclient, a fork of the MySQL-python interface for the MySQL database.
mysqlclient-1.3.8-cp27-cp27m-win32.whl
mysqlclient-1.3.8-cp27-cp27m-win_amd64.whl
mysqlclient-1.3.8-cp34-cp34m-win32.whl
mysqlclient-1.3.8-cp34-cp34m-win_amd64.whl
mysqlclient-1.3.8-cp35-cp35m-win32.whl
mysqlclient-1.3.8-cp35-cp35m-win_amd64.whl
mysqlclient-1.3.8-cp36-cp36m-win32.whl
mysqlclient-1.3.8-cp36-cp36m-win_amd64.whl
2
我之前也遇到过类似的问题,就是在安装 MySQL-python 时总是出错。我试过用 easy_install 和 pip,但都遇到了关于 vcvarsall.bat 的问题。下面是我解决这个问题的方法,希望能给你一些启发。我用的是 Windows 8 系统,安装了 Python 2.7,并通过 Eclipse 来运行我的程序。
一些背景:
当我使用 easy_install
时,它试图安装 MySQL-python 1.2.5
,结果失败了,提示 error: Unable to find vcvarsall.bat
。我又用 easy_install
安装了 pip
,然后尝试用 pip
安装,但也遇到了类似的错误。它们都提到了 vcvarsall.bat
,这个文件是和 Visual Studio 有关的。因为我电脑上没有安装 Visual Studio,所以我只能寻找其他解决方案,下面就是我找到的方法。
解决方案:
- 从 https://www.python.org/download 重新安装 Python 2.7.8,这样可以添加一些缺失的注册表设置,这对后面的安装是必要的。
- 从 http://pypi.python.org/pypi/MySQL-python/1.2.4 安装 1.2.4 版本。
在完成这两个安装后,我就能通过 Eclipse 查询我的 MySQL 数据库了。