我已经在这个2天的时间里撞到了我的头上,并且没有取得进展。
我正在尝试在我的Windows 8(恨Windows 8)框上安装Python MySQL连接器。
我正在使用Python 2.7。 我原来收到一个错误:
找不到vcvarsall.bat。
我做了一些调查,发现我需要在我的盒子上安装VS 2008(VC ++编译器),我安装了快速版本。 我还将ProductDir值与vcvarsall.bat的path添加到我的registry中的以下项:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC.
我还添加了VS90COMNTOOLS环境variables与vcvarsall.bat的path。 我运行以下命令时仍然出现错误:
pip install MySQL-python
您可以提供的任何input是非常感谢…谢谢…
该错误在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可执行文件。 你可以在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
的有用的评论。)