7

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

HaydnHuntley
  • 71
  • 1
  • 1
  • 3
  • Have you tried running "apt-get update" prior to running the install? – Patrick Kelly Aug 17 '20 at 19:15
  • 1
    You should not expect to get any support for Python 2 anymore. It has reached its end of life at the beginning of this year. You should focus on making your code work with Python 3. – mkrieger1 Aug 17 '20 at 19:20
  • Thank you Patrick, but I did "apt-get update" prior to running the install. – HaydnHuntley Aug 18 '20 at 20:10
  • 1
    Thank you mkrieger1, I understand that Python 2.x has reached end-of-life, but I'm working in an environment where we have quite a few computers, running various versions of Linux. Some of the oldest are embedded systems tied to medium-sized (1.8m) telescopes, so the lesser of the two evils will be to roll back to Ubuntu 18.04 and stay with it, rather than rewriting everything to work with Python 3. – HaydnHuntley Aug 18 '20 at 20:19
  • This page might lead one to believe that python-mysqldb might be available for 20.04: (https://www.ubuntuupdates.org/package/core/focal/main/base/python-mysqldb) – HaydnHuntley Aug 18 '20 at 20:19
  • However this page shows that it is only available in 16.04, 18.04, and 19.10, but not in 20.04: (https://packages.ubuntu.com/search?keywords=python-mysqldb&searchon=names) – HaydnHuntley Aug 18 '20 at 20:21
  • I'd even consider using PIP, if that was available in 20.04 for Python 2.x – HaydnHuntley Aug 18 '20 at 20:22

2 Answers2

6

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
panticz
  • 2,135
  • 25
  • 16
1

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