安装 mysql-python (Windows)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21440230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install mysql-python (Windows)
提问by Myone
I've spent hours trying to make Django work on my computer. The problem is that I can't install the mysql-python package. I'm running Windows 7 64bit. This is what I've tried:
我花了几个小时试图让 Django 在我的电脑上工作。问题是我无法安装 mysql-python 包。我正在运行 Windows 7 64 位。这是我尝试过的:
- I have downloaded easy_install
- I have downloaded Cygwin64 to be able to run Linux commands (Win cmd was driving me crazy)
- I have typed in: easy_install mysql-python (gave me an error message saying it can't find vcvarsall.bat)
- I have downloaded Visual Studio 2010. However, I uninstalled it since I found out that I had some other version of it already (it didn't solve the problem)
- 我已经下载了easy_install
- 我已经下载了 Cygwin64 以便能够运行 Linux 命令(Win cmd 快把我逼疯了)
- 我输入了:easy_install mysql-python(给我一条错误消息,说它找不到 vcvarsall.bat)
- 我已经下载了 Visual Studio 2010。但是,我卸载了它,因为我发现我已经有了它的其他版本(它没有解决问题)
I have googled this problem like a thousand times, so I would be very grateful if someone could help me. Thanks in advance!
我已经在谷歌上搜索了这个问题一千次,所以如果有人能帮助我,我将不胜感激。提前致谢!
EDIT: I discovered this: https://pypi.python.org/pypi/MySQL-python/1.2.5. Does this mean I can't run Django with python 3.3? And why bother to go through all this work if there is an .exe-file out there?
编辑:我发现了这个:https://pypi.python.org/pypi/MySQL-python/1.2.5。这是否意味着我不能用 python 3.3 运行 Django?如果有一个 .exe 文件,为什么还要费心去完成所有这些工作呢?
采纳答案by Aaron Lelevier
You're going to want to add Python to your Path Environment Variable in this way. Go to:
您将希望以这种方式将 Python 添加到您的路径环境变量中。去:
- My Computer
- System Properties
- Advance System Settings
- Under the "Advanced" tab click the button that says "Environment Variables"
- Then under System Variables you are going to want to add / change the following variables:
PYTHONPATHandPath. Here is a paste of what my variables look like:
- 我的电脑
- 系统属性
- 高级系统设置
- 在“高级”选项卡下,单击“环境变量”按钮
- 然后在系统变量下,您将要添加/更改以下变量:
PYTHONPATH和Path. 这是我的变量外观的粘贴:
PYTHONPATH
路径
C:\Python27;C:\Python27\Lib\site-packages;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\Python27\Scripts
Path
小路
C:\Program Files\MySQL\MySQL Utilities 1.3.5\;C:\Python27;C:\Python27\Lib\site-packages;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\Python27\Scripts
Your Path's might be different, so please adjust them, but this configuration works for me and you should be able to run MySQL after making these changes.
你的路径可能不同,所以请调整它们,但这个配置对我有用,你应该能够在进行这些更改后运行 MySQL。
回答by CFreitas
回答by James Oravec
I have a slightly different setup, but think my solution will help you out.
我的设置略有不同,但认为我的解决方案会对您有所帮助。
I have a Windows 8 Machine, Python 2.7 installed and running my stuff through eclipse.
我有一台 Windows 8 机器,安装了 Python 2.7 并通过 eclipse 运行我的东西。
Some Background:
一些背景:
When I did an easy installit tries to install MySQL-python 1.2.5which failed with an error: Unable to find vcvarsall.bat. I did an easy_installof pipand tried the pipinstall which also failed with a similar error. They both reference vcvarsall.batwhich is something to do with visual studio, since I don't have visual studio on my machine, it left me looking for a different solution, which I share below.
当我执行easy install它时,它尝试安装MySQL-python 1.2.5失败并带有error: Unable to find vcvarsall.bat. 我做了easy_install的pip,并试图pip安装也失败,类似的错误。他们都参考vcvarsall.bat了与visual studio有关的东西,因为我的机器上没有visual studio,这让我寻找不同的解决方案,我在下面分享。
The Solution:
解决方案:
- Reinstall python 2.7.8 from 2.7.8 from https://www.python.org/downloadthis will add any missing registry settings, which is required by the next install.
- Install 1.2.4 from http://pypi.python.org/pypi/MySQL-python/1.2.4
- 从https://www.python.org/download从 2.7.8 重新安装 python 2.7.8这将添加任何丢失的注册表设置,这是下次安装所需的。
- 从http://pypi.python.org/pypi/MySQL-python/1.2.4安装 1.2.4
After I did both of those installs I was able to query my MySQL db through eclipse.
在我完成这两个安装后,我能够通过 eclipse 查询我的 MySQL 数据库。
回答by Vicky Zhang
For folks using Python 3.0+ (which should be everyone now):
对于使用 Python 3.0+ 的人(现在应该是每个人):
Unfortunately, MySQL-Python 1.2.5 does not support Python 3.0+ yet (which is kinda unreasonable IMHO, Python 3+ has been out for a while). Reference : https://pypi.python.org/pypi/MySQL-python/1.2.5
不幸的是,MySQL-Python 1.2.5 还不支持 Python 3.0+(恕我直言,这有点不合理,Python 3+ 已经推出一段时间了)。参考:https: //pypi.python.org/pypi/MySQL-python/1.2.5
So, my workaround is to use Oracle's MySQL connector. In settings.py, change DATABASE's 'ENGINE' field to: 'ENGINE': 'mysql.connector.django',
所以,我的解决方法是使用 Oracle 的 MySQL 连接器。在 settings.py 中,将 DATABASE 的 'ENGINE' 字段更改为:'ENGINE': 'mysql.connector.django',
More info could be found in the last paragraph of the first answer to this question: Setting Django up to use MySQL
更多信息可以在这个问题的第一个答案的最后一段中找到:Setting Django up to use MySQL
Hope this helps!!
希望这可以帮助!!
回答by Ortal Blumenfeld Lagziel
try running the following command:
尝试运行以下命令:
pip install mysqlclient
回答by Laura Chesches
if you use the site http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python, download the file:
如果您使用网站http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python,请下载文件:
mysqlclient?1.3.6?cp34?none?win32.whl or
mysqlclient?1.3.6?cp34?none?win_amd64.whl
mysqlclient?1.3.6?cp34?none?win32.whl 或
mysqlclient?1.3.6?cp34?none?win_amd64.whl
depending on the version of python you have (these are for python 3.4) and the type of windows you have (x64 or x32)
取决于您拥有的 Python 版本(这些适用于 Python 3.4)和您拥有的 Windows 类型(x64 或 x32)
extract this file into C:\Python34\Lib\site-packages and your project will work
将此文件解压缩到 C:\Python34\Lib\site-packages 中,您的项目将工作
回答by Alfred Huang
If you are trying to use mysqlclienton WINDOWSwith this failure, try to install the lower version instead:
如果您尝试mysqlclient在WINDOWS 上使用失败,请尝试安装较低版本:
pip install mysqlclient==1.3.4
回答by Ashish Gupta
MySqldb python install windows
MySqldb python 安装窗口
MySQL-python 1.2.3 for Windows and Python 2.7, 32bit and 64bit versions
MySQL-python 1.2.3 for Windows 和 Python 2.7,32 位和 64 位版本
回答by kaya
If you encounter the problem with missing MS VC 14 Build tools while trying pip install mysqlclienta possible solution for this may be https://stackoverflow.com/a/51811349/1552410
如果您在尝试pip install mysqlclient可能的解决方案时遇到缺少 MS VC 14 构建工具的问题可能是https://stackoverflow.com/a/51811349/1552410
回答by Kamal Maharana
Just Download mysqlclient from here https://www.lfd.uci.edu/~gohlke/pythonlibs/be careful while downloading the right version depending on your your python version installed. Then proceed with the import. It worked for me because in my case the error was telling to install Visual Studio C++ 14.0 something which wasted my time and occupied around 10GB of space in my C drive. So recommending installing mysqlclient using pip install mysqlclient
只需从这里下载 mysqlclient https://www.lfd.uci.edu/~gohlke/pythonlibs/根据您安装的 python 版本下载正确的版本时要小心。然后继续导入。它对我有用,因为在我的情况下,错误告诉我安装 Visual Studio C++ 14.0 的东西浪费了我的时间并在我的 C 驱动器中占用了大约 10GB 的空间。所以推荐使用 pip install mysqlclient 安装mysqlclient

