Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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

like image 478
HaydnHuntley Avatar asked Aug 17 '20 19:08

HaydnHuntley


2 Answers

Also you can just add the Ubuntu 18.04 repositoery to install the python-mysqldb package:

sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu bionic main'
sudo apt update
sudo apt install -y python-mysqldb
like image 182
panticz Avatar answered Sep 24 '22 11:09

panticz


This will download, build and install it for all users, using 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 directory

like image 41
Davide Capodaglio Avatar answered Sep 22 '22 11:09

Davide Capodaglio