Reputation: 8995
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.
Upvotes: 5
Views: 11593
Reputation: 11
follow this steps in terminal!!!
brew install mysql
brew install openssl
export PATH=${PATH}:/usr/local/mysql/bin/
sudo xcode-select --reset
pip install mysqlclient
Upvotes: 1
Reputation: 21
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.
Upvotes: 1
Reputation: 1895
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 was3.10
:$ python3 --version Python 3.10.6
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.
Upvotes: 4
Reputation: 141
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/
Upvotes: 13
Reputation: 8995
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.
Upvotes: 6
Reputation: 452
Assuming the requirements.txt is holding an 'import mysql' statement, MySQL documentation help resolves this issue in two ways:
Once the dependencies are installed you can avoid code any rewriting by installing the mysql package.
Upvotes: 0