简体   繁体   English

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

[英]How to install python-mysqldb for Python 2.7 in Ubuntu 20.04 (Focal Fossa)?

I've tried "apt-get install python-mysqldb" which results in:我试过“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

Note: "apt-get install python3-mysqldb" works, however I have a lot of code written for Python 2.x which no longer runs, and this is causing enough problems that I'm probably going to have to reinstall Ubuntu 18.04注意:“apt-get install python3-mysqldb”可以工作,但是我有很多为 Python 2.x 编写的代码不再运行,这导致了很多问题,我可能不得不重新安装 Ubuntu 18.04

Also you can just add the Ubuntu 18.04 repositoery to install the python-mysqldb package:您也可以添加 Ubuntu 18.04 存储库来安装 python-mysqldb package:

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

This will download, build and install it for all users, using pip这将为所有用户下载、构建和安装它,使用 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

Answer found from MySQLdb install error - _mysql.c:44:23: error: my_config.h: No such file or directoryMySQLdb 安装错误找到答案 - _mysql.c:44:23: error: my_config.h: No such file or directory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM