如何在Ubuntu 20.04(Focal Fossa)中为Python 2.7安装python-mysqldb?

时间:2020-08-17 19:10:52

标签: python-2.7 ubuntu mysql-python

我尝试了“ apt-get install python-mysqldb”,结果是:

root@ps1svr:~# apt-get install python-mysqldb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package python-mysqldb is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-mysqldb' has no installation candidate

注意:“ apt-get install python3-mysqldb”有效,但是我为Python 2.x编写了很多不再运行的代码,这引起了很多问题,我可能必须重新安装Ubuntu 18.04

2 个答案:

答案 0 :(得分:2)

您也可以添加 Ubuntu 18.04 存储库来安装 python-mysqldb 包:

sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu bionic main'
sudo apt update
sudo apt install -y python-mysqldb

答案 1 :(得分:0)

这将使用 pip 为所有用户下载、构建和安装它

sudo apt install libmysqlclient-dev python2.7-dev

wget https://bootstrap.pypa.io/get-pip.py
sudo python2.7 get-pip.py

sudo wget https://raw.githubusercontent.com/paulfitz/mysql-connector-c/master/include/my_config.h -O /usr/include/mysql/my_config.h

sudo pip2 install MySQL-python

MySQLdb install error - _mysql.c:44:23: error: my_config.h: No such file or directory找到的答案