如何使用pip安装Python的MySQLdb模块?


当前回答

我在通过Pip(问题编译源)在Windows上安装64位版本的MySQLdb时遇到了问题[32位版本安装ok]。设法从http://www.lfd.uci.edu/~gohlke/pythonlibs/上的.whl文件安装编译后的MySQLdb

然后,.whl文件可以通过pip作为https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels中的文档安装

例如,如果你保存在C:/ the,你可以安装通过

pip install c:/MySQL_python-1.2.5-cp27-none-win_amd64.whl

后续:如果你安装了64位版本的Python,那么你想从上面的链接安装64位AMD版本的MySQLdb[即,即使你有英特尔处理器]。如果你尝试安装32位版本,我认为你会在下面的评论中得到不支持的轮子错误。

其他回答

PIP安装mysql-connector-python 如文档中所述:

https://dev.mysql.com/doc/connector-python/en/connector-python-installation-binary.html

在RHEL 7:

Sudo yum安装yum-utils mariadb-devel python-pip python-devel GCC

sudo /bin/pip2 install MySQL-python

我尝试了所有的选项,但不能让它在红帽平台上工作。 我做了下面的工作:-

yum install MySQL-python -y

一旦包被安装,就可以在解释器中导入模块如下

>>> import MySQLdb
>>> 

如果你使用的是树莓派(Raspberry Pi)

首先需要安装pip命令

apt-get install python-pip

这就是按顺序安装

apt-get install python-dev libmysqlclient-dev

apt-get install python-pip

pip install MySQL-python

对于Python3,我需要这样做:

python3 -m pip install MySQL