mysqlclient-1.4.6 now fails to install (Python 3.9) when it did under 3.6 (SOLVED)

Viewed 1635

When I try to use pip3 install -r requirements.txt now that my virtualenv (and my host Python version) is somehow 3.9 instead of 3.6 as it used to be, installation of mysqlclient=1.4.6 now fails this way:

Complete output (12 lines):
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup.py", line 16, in <module>
    metadata, options = get_config()
  File "/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup_posix.py", line 61, in get_config
    libs = mysql_config("libs")
  File "/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup_posix.py", line 29, in mysql_config
    raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found

The mysql_config script does exist on this system as: /usr/local/mysql-5.7.16-osx10.11-x86_64/bin/mysql_config but I don't know how it is supposed to be located by the installer. And, I don't know why it's failing now when it didn't fail then. Please advise.

2 Answers

It seems to have failed while trying to run several mysql related binaries from a python script. Try to set your system's PATH environment to allow the install script to find the mysql related binaries.

PATH="/usr/local/mysql-5.7.16-osx10.11-x86_64/bin:$PATH" pip3 install -r requirements.txt

P.S. I tried to reproduce the installation with the same Python 3.9, mysqlclient 1.4.6 in my Mac environment, and it was installed normally.

$ python --version
Python 3.9.4

$ which mysql_config
/opt/homebrew/opt/mysql@5.7/bin/mysql_config

$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip install mysqlclient==1.4.6
Collecting mysqlclient==1.4.6
  Downloading mysqlclient-1.4.6.tar.gz (85 kB)
     |████████████████████████████████| 85 kB 1.8 MB/s
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.4.6

I found my own answer!

In this case:

export PATH=/usr/local/mysql-5.7.6-0sx10.11-x86_64/bin:$PATH

(This being the directory where I separately discovered that the mysql_config script is installed on my computer – see above.) The problem was that the file wasn't in the $PATH. The above command adds it to the beginning of the path list for the duration of the present terminal session.

... then repeat the pip3 install command as above, and now it works.

Related