如何使用 pip 安装 Python MySQLdb 模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25865270/
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
How to install Python MySQLdb module using pip?
采纳答案by Marian
It's easy to do, but hard to remember the correct spelling:
这很容易做到,但很难记住正确的拼写:
pip install mysqlclient
If you need 1.2.x versions (legacy Python only), use pip install MySQL-python
如果您需要 1.2.x 版本(仅限旧版 Python),请使用 pip install MySQL-python
Note: Some dependencies might have to be in place when running the above command. Some hints on how to install these on various platforms:
注意:运行上述命令时,某些依赖项可能必须到位。关于如何在各种平台上安装这些的一些提示:
Ubuntu 14, Ubuntu 16, Debian 8.6 (jessie)
Ubuntu 14、Ubuntu 16、Debian 8.6(杰西)
sudo apt-get install python-pip python-dev libmysqlclient-dev
Fedora 24:
软呢帽 24:
sudo dnf install python python-devel mysql-devel redhat-rpm-config gcc
Mac OS
苹果系统
brew install mysql-connector-c
if that fails, try
如果失败,请尝试
brew install mysql
回答by d-coder
I had the same problem too.Follow these steps if you are on Windows. Go to: 1.My Computer 2.System Properties 3.Advance System Settings 4. Under the "Advanced" tab click the button that says "Environment Variables" 5. Then under System Variables you have to add / change the following variables: PYTHONPATH and Path. Here is a paste of what my variables look like: python path:
我也遇到了同样的问题。如果您使用的是 Windows,请按照以下步骤操作。转到:1.我的电脑 2.系统属性 3.高级系统设置 4.在“高级”选项卡下单击“环境变量”按钮 5.然后在系统变量下,您必须添加/更改以下变量:PYTHONPATH和路径。这是我的变量外观的粘贴:python 路径:
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
See this link for reference
请参阅此链接以供参考
回答by Ray Kiddy
Starting from a fresh Ubuntu 14.04.2 system, these two commands were needed:
从全新的 Ubuntu 14.04.2 系统开始,需要这两个命令:
apt-get install python-dev libmysqlclient-dev
pip install MySQL-python
Just doing the "pip install" by itself did not work.
单独执行“pip install”是行不通的。
From http://codeinthehole.com/writing/how-to-set-up-mysql-for-python-on-ubuntu/
来自http://codeinthehole.com/writing/how-to-set-up-mysql-for-python-on-ubuntu/
回答by kyrenia
I had problems installing the 64-bit version of MySQLdb on Windows via Pip (problem compiling sources) [32bit version installed ok]. Managed to install the compiled MySQLdb from the .whl file available from http://www.lfd.uci.edu/~gohlke/pythonlibs/
我在通过 Pip 在 Windows 上安装 64 位版本的 MySQLdb 时遇到问题(编译源有问题)[32 位版本安装正常]。设法从http://www.lfd.uci.edu/~gohlke/pythonlibs/提供的 .whl 文件安装编译好的 MySQLdb
The .whl file can then be installed via pip as document in https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels
然后可以通过 pip 作为文档安装 .whl 文件https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels
For example if you save in C:/the you can install via
例如,如果您保存在C:/您可以通过安装
pip install c:/MySQL_python-1.2.5-cp27-none-win_amd64.whl
pip install c:/MySQL_python-1.2.5-cp27-none-win_amd64.whl
Follow-up: if you have a 64bit version of Python installed, then you want to install the 64-bit AMD version of MySQLdb from the link above [i.e. even if you have a Intel processor]. If you instead try and install the 32-bit version, I think you get the unsupported wheel error in comments below.
后续:如果您安装了 64 位版本的 Python,那么您想从上面的链接安装 64 位 AMD 版本的 MySQLdb [即,即使您有英特尔处理器]。如果您尝试安装 32 位版本,我认为您会在下面的评论中看到不支持的轮错误。
回答by Tanakorn Lueangkajonvit
If you are use Raspberry Pi [Raspbian OS]
如果您使用的是 Raspberry Pi [Raspbian OS]
There are need to be install pip command at first
首先需要安装pip命令
apt-get install python-pip
So that just install Sequently
这样就可以依次安装
apt-get install python-dev libmysqlclient-dev
apt-get install python-pip
pip install MySQL-python
回答by Ashwin
I tried all the option but was not able to get it working on Redhat platform. I did the following to make it work:-
我尝试了所有选项,但无法在 Redhat 平台上运行。我做了以下工作以使其工作:-
yum install MySQL-python -y
Once the package was installed was able to import module as follows in the interpreter:-
安装包后,就可以在解释器中按如下方式导入模块:-
>>> import MySQLdb
>>>
回答by Vast
The above answer is great, but there may be some problems when we using pip to install MySQL-python in Windows
上面的回答很好,但是我们在Windows下使用pip安装MySQL-python时可能会出现一些问题
for example,It needs some files that are associated with Visual Stdio.One solution is installing VS2008 or 2010……Obviously,it cost too much.
例如,它需要一些与Visual Stdio相关联的文件。一种解决方案是安装 VS2008 或 2010……显然,成本太高了。
Another way is the answer of @bob90937 . I am here to do something to add.
另一种方式是@bob90937 的答案。我是来做些补充的。
with http://www.lfd.uci.edu/~gohlke/pythonlibs, u can download many Windows binaries of many scientific open-source extension packages for the official CPython distribution of the Python programming language.
通过http://www.lfd.uci.edu/~gohlke/pythonlibs,您可以为 Python 编程语言的官方 CPython 发行版下载许多科学开源扩展包的许多 Windows 二进制文件。
Back to topic,we can choose the MySQL-python(py2)or Mysqlclient(py3)and use pip install to install. it gives us Great convenience!
回到主题,我们可以选择MySQL-python(py2)或Mysqlclient(py3)并使用pip install进行安装。它给我们带来了极大的方便!
回答by kinsley kajiva
well this worked for me:
这对我有用:
pip install mysqlclient
this is for python 3.x
这是用于 python 3.x
回答by Frank Harb
For Python3 I needed to do this:
对于 Python3,我需要这样做:
python3 -m pip install MySQL


