4

Well, I have "googled it" without finding an answer. Routine updates of a Python-based site, based on its requirements.txt, now fail with metadata-generation-failed when attempting to update "mysqlclient." The question is why.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
  • Please, before anyone "votes this question off the island," will anyone please explain to me what the "metadata" is, and how it is generated, and why such a process might "fail?" Before I "dumpster-dive into the script code" to find out for myself, it seems perfectly reasonable for me to ... ask politely. – Mike Robinson Jun 08 '22 at 00:26
  • 1
    You will have to provide much more details. – Klaus D. Jun 08 '22 at 01:04
  • 1
    I have no idea what `metdata` it uses but maybe with FULL error message it could be simpler to guess it. – furas Jun 08 '22 at 01:21
  • To a Python programmer this question is perfectly clear. The "pip" update process is handing back an error-message from a subprocess. And the text of that message is literally: `metadata-generation-failed`. And the package being installed is `mysqlclient`. – Mike Robinson Jun 08 '22 at 02:28
  • Problem SOLVED. See below. – Mike Robinson Jun 08 '22 at 16:57
  • what package is in the requirements.txt that is causing this to fail? – brddawg Jun 09 '22 at 15:49

6 Answers6

12

Robinson`s answer is correct, but also maybe you forgot to install MySQL development headers and libraries like so:

$ sudo apt-get install default-libmysqlclient-dev

details: https://pypi.org/project/mysqlclient/

Levinson
  • 131
  • 1
  • 4
6

The relevant message text was as follows:

Collecting mysqlclient
  Using cached mysqlclient-2.1.0.tar.gz (87 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      /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 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/zv/60vkqgms41v8zg76_n8rntg00000gn/T/pip-install-_nlyaw6p/mysqlclient_a781e05976524422b764a6902ff6fe88/setup.py", line 15, in <module>
          metadata, options = get_config()
        File "/private/var/folders/zv/60vkqgms41v8zg76_n8rntg00000gn/T/pip-install-_nlyaw6p/mysqlclient_a781e05976524422b764a6902ff6fe88/setup_posix.py", line 70, in get_config
          libs = mysql_config("libs")
        File "/private/var/folders/zv/60vkqgms41v8zg76_n8rntg00000gn/T/pip-install-_nlyaw6p/mysqlclient_a781e05976524422b764a6902ff6fe88/setup_posix.py", line 31, in mysql_config
          raise OSError("{} not found".format(_mysql_config_path))
      OSError: mysql_config not found
      mysql_config --version
      mariadb_config --version
      mysql_config --libs
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

And this is what provided the clue: mysql_config: command not found

I solved the problem by locating where the command was on my system, and adding it to the $PATH, which in my case was as follows:

export PATH=/usr/local/mysql-5.7.16-osx10.11-x86_64/bin:$PATH

Apparently the meaning of this message is that a command to configure mysql could not be found on the $PATH. Now we know.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
3

Short answer

sudo apt-get install python3.10-dev default-libmysqlclient-dev build-essential

Version of python within python3.10-dev should be the version of python you use. In my case it was 3.10:

$ python3 --version
Python 3.10.6

Details

First, I ran @levinson's command:

sudo apt-get install default-libmysqlclient-dev

Then during pip install -r requirements.txt I got other errors (inherited one another):

Building wheel for mysqlclient (setup.py) ... error
error: subprocess-exited-with-error
<...>
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
<...>
Running setup.py install for mysqlclient ... error
error: subprocess-exited-with-error
<...>
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

After that, I found this article which suggests executing this command:

# For Debian/ Ubuntu
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

But it gives me error while installing python3-dev. After that I found out that there's a python3.x-dev packages and tried 3.10 version. And it worked! After that I just ran pip install -r requirements.txt and the installation was successful.

egvo
  • 1,493
  • 18
  • 26
1

Not sure if this is still helpful. In my case I realized that

sudo apt-get install default-libmysqlclient-dev

was installing the mysql client but not the mysql server. I installed the mysql server with:

sudo apt install mysql-server

and that fixed the issue.

Ropacus
  • 11
  • 3
0

Assuming the requirements.txt is holding an 'import mysql' statement, MySQL documentation help resolves this issue in two ways:

  1. Since mysql is a 'virtual package' install "MySQL-python (Python 2) or mysqlclient (Python 3)"
  2. Resolve OS specific install dependencies

Once the dependencies are installed you can avoid code any rewriting by installing the mysql package.

brddawg
  • 434
  • 8
  • 19
0

follow this steps in terminal!!!

  1. brew install mysql

  2. brew install openssl

  3. export PATH=${PATH}:/usr/local/mysql/bin/

  4. sudo xcode-select --reset

  5. pip install mysqlclient

Edward
  • 1