如何使用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

这很容易,但很难记住正确的拼写:

pip install mysqlclient

如果你需要1.2。x版本(仅适用于遗留的Python),使用pip安装MySQL-python

注意:在运行上述命令时,有些依赖项可能必须就位。一些关于如何在不同平台上安装这些工具的提示:

Ubuntu 14, Ubuntu 16, Debian 8.6 (jessie)

sudo apt-get install python-pip python-dev libmysqlclient-dev

Fedora 24:

sudo dnf install python python-devel mysql-devel redhat-rpm-config gcc

苹果操作系统

brew install mysql-connector-c

如果失败了,那就试试

brew install mysql

对于Python3,我需要这样做:

python3 -m pip install MySQL

我也有同样的问题。如果您使用的是Windows,请遵循这些步骤。 至: 1.我的电脑 2.系统属性 3.系统高级设置 4. 在“高级”选项卡下单击“环境变量”按钮 5. 然后在“系统变量”下,您必须添加/更改以下变量:PYTHONPATH和Path。下面是我的变量的粘贴: python路径:

C:\Python27;C:\Python27\Lib\site-packages;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\Python27\Scripts

路径:

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

参考这个链接

在RHEL 7:

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

sudo /bin/pip2 install MySQL-python