python安装mysql-client
python安装mysql-client
Arch系的Manjaro在近几年变得异常火热,使用manjaro作为开发机开发Python时,不可避免需要安装mysqlclient包来连接Mysql进行开发,但是mysqlclient无论是Win是CentOS还是Ubuntu,都无法正确安装,这里呢就给出几个解决方案。
ArchLinux(或Manjaro)
Arch(或Manjaro)使用pacman包管理器,在其包资源中有一个python-mysqlclient包,直接通过pacman安装即可。
pacman -S python-mysqlclient
CentOS(红帽)
CentOS有Python、Mysql的开发工具包,安装后使用pip安装mysqlclient即可
yum install mysql-devel
yum install python-devel
pip install mysqlclient
Ubuntu
Ubuntu的话,也是安装一些Mysql的依赖或开发库
apt-get install libmysql-dev
apt-get install libmysqlclient-dev
apt-get install python-dev #python3要装python3-dev
pip install mysqlclient
此时如果遇到如下错误
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'setuptools'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-p8wpb1kf/mysqlclient/
需要安装一下setuptools包,直接pip install setuptools,python3的话就pip3,看你的系统。
Win
anaconda
直接下载使用anaconda,创建虚拟环境来进行开发
whl包安装
或者到pipy下载相对应的whl包,使用pip安装即可,具体包的版本和适用平台自行查询就好,网上资源很多也很有效
到这个地址下载自己版本对应的资源
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
pip install mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl
麒麟操作系统
yum install mysql-devel
yum install python-devel
pip install mysqlclient
mysql-devel安装会失败,找不到。可通过下面地址下载rpm包
https://archive.kylinos.cn/yum/v10/sp1-openstack-q/aarch64/os/Packages/m/
rpm安装mysql-devel会提示依赖,按照提示依次安装即可。