在这件事上,我头撞墙已经两天多了,没有任何进展。
我正试图在我的Windows 8(讨厌windows8)框中安装Python MySQL连接器。
我正在使用Python2.7。我最初收到一个错误:
找不到vcvarsall.bat。
我做了一些研究,发现我需要VS 2008(VC++编译器)安装在我的盒子里,我安装了Express版本。我还将ProductDir值和vcvarsall.bat的路径添加到注册表中的以下项:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC.
我还添加了VS90COMNTOOLS环境变量,路径为vcvarsall.bat。当我运行以下命令时,仍然会出现错误:
pip install MySQL-python
你能提供的任何意见都非常感谢。。。谢谢。。。
错误列在pip.log的以下代码段中:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\t\appdata\local\temp\pip_build_T\MySQL-python\setup.py", line 21, in <module>
setuptools.setup(**metadata)
File "C:\Python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "build\bdist.win-amd64\egg\setuptools\command\install.py", line 53, in run
File "C:\Python27\lib\distutils\command\install.py", line 563, in run
self.run_command('build')
File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "build\bdist.win-amd64\egg\setuptools\command\build_ext.py", line 52, in run
File "C:\Python27\lib\distutils\command\build_ext.py", line 337, in run
self.build_extensions()
File "C:\Python27\lib\distutils\command\build_ext.py", line 446, in build_extensions
self.build_extension(ext)
File "build\bdist.win-amd64\egg\setuptools\command\build_ext.py", line 186, in build_extension
File "C:\Python27\lib\distutils\command\build_ext.py", line 496, in build_extension
depends=ext.depends)
File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile
self.initialize()
File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize
vc_env = query_vcvarsall(VERSION, plat_spec)
File "C:\Python27\lib\distutils\msvc9compiler.py", line 299, in query_vcvarsall
raise ValueError(str(list(result.keys())))
ValueError: [u'path']
----------------------------------------
Cleaning up...
Removing temporary dir c:\users\t\appdata\local\temp\pip_build_T...
Command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\t\\appdata\\local\\temp\\pip_build_T\\MySQL-python\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\t\appdata\local\temp\pip-d5hmns-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\t\appdata\local\temp\pip_build_T\MySQL-python
Exception information:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip-1.5.4-py2.7.egg\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip-1.5.4-py2.7.egg\pip\commands\install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "C:\Python27\lib\site-packages\pip-1.5.4-py2.7.egg\pip\req.py", line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "C:\Python27\lib\site-packages\pip-1.5.4-py2.7.egg\pip\req.py", line 706, in install
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
File "C:\Python27\lib\site-packages\pip-1.5.4-py2.7.egg\pip\util.py", line 697, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\t\\appdata\\local\\temp\\pip_build_T\\MySQL-python\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\t\appdata\local\temp\pip-d5hmns-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\t\appdata\local\temp\pip_build_T\MySQL-python
最佳答案
pip install
失败表明对编译的文件有一些潜在的依赖性。另一种方法是使用https://pypi.python.org/pypi/MySQL-python中的.exe安装程序,但这不适合virtualenvs,对于64位Python将失败(它将抱怨即使安装了Python 2.7,也无法在注册表中找到它)。
幸运的是,Christoph Gohlke维护了一些非官方的Windows二进制文件,这些文件是pip可安装的。您可以在http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python找到它们
现在可以从您的主Python环境或virtualenv中调用pip install C:/PATH/TO/MySQL_python‑1.2.5‑cp27‑none‑win_amd64.whl
。
理想情况下,这样的轮子将通过MySQL python PyPI页面提供,此时一个简单的pip install
将起作用。
(这个答案基于Carsten
的有用评论。)