Mac OS X - EnvironmentError: mysql_config not found
Solution 1
I had been debugging this problem forever - 3 hours 17 mins. What particularly annoyed me was that I already had sql installed on my system through prior uni work but pip/pip3 wasn't recognising it. These threads above and many other I scoured the internet for were helpful in eluminating the problem but didn't actually solve things.
ANSWER
Pip is looking for mysql binaries in the Homebrew Directory which is located relative to Macintosh HD @
/usr/local/Cellar/
so I found that this requires you making a few changes
step 1: Download MySql if not already done so https://dev.mysql.com/downloads/
Step 2: Locate it relative to Macintosh HD and cd
/usr/local/mysql/bin
Step 3: Once there open terminal and use a text editor of choice - I'm a neovim guy myself so I typed (doesn't automatically come with Mac... another story for another day)
nvim mysql_config
Step 4: You will see at approx line 112
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
Change to
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
*you'll notice that this file has read-only access so if your using vim or neovim
:w !sudo tee %
Step 5: Head to the home directory and edit the .bash_profile file
cd ~
Then
nvim .bash_profile
and add
export PATH="/usr/local/mysql/bin:$PATH"
to the file then save
Step 6: relative to Macintosh HD locate paths and add to it
cd /private/etc/
then
nvim paths
and add
/usr/local/mysql/bin
*you'll again notice that this file has read-only access so if your using vim or neovim
:w !sudo tee %
then
cd ~
then refresh the terminal with your changes by running
source .bash_profile
Finally
pip3 install mysqlclient
And Viola. Remember it's a vibe.
Solution 2
If you don't want to install full mysql, we can fix this by just installing mysqlclient
brew install mysqlclient
Once cmd is completed it will ask to add below line to ~/.bash_profile
:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
Close terminal and start new terminal and proceed with pip install mysqlclient
Solution 3
I am running Python 3.6 on MacOS Catalina. My issue was that I tried to install mysqlclient==1.4.2.post1
and it keeps throwing mysql_config not found error.
This is the steps I took to solve the issue.
- Install mysql-connector-c using brew (if you have mysql already install unlink first
brew unlink mysql
) -brew install mysql-connector-c
- Open mysql_config and edit the file around line 112
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
-
brew info openssl
- this will give you more information on what needs to be done about putting openssl in PATH - in relation to step 3, you need to do this to put openssl in PATH -
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
- for compilers to find openssl -
export LDFLAGS="-L/usr/local/opt/openssl/lib"
- for compilers to find openssl -
export CPPFLAGS="-I/usr/local/opt/openssl/include"
Solution 4
Also this happens when I was installing mysqlclient,
$ pip install mysqlclient
As user3429036 said,
$ brew install mysql
Solution 5
brew install mysql
added mysql to /usr/local/Cellar/...
, so I needed to add :/usr/local/Cellar/
to my $PATH
and then which mysql_config
worked!
daniel_c05
Updated on October 08, 2020Comments
-
daniel_c05 over 3 years
First off, yeah, I've already seen this:
pip install mysql-python fails with EnvironmentError: mysql_config not found
The problem
I am trying to use Django on a Google App Engine project. However, I haven't been able to get started as the server fails to start properly due to:
ImproperlyConfigured("Error loading MySQLdb module: %s" % e) ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I did some research and it all pointed to having to install Mysql-python, as apparently it isn't on my system. I actually tried uninstalling it and got this:
Cannot uninstall requirement mysql-python, not installed
Whenever I actually do try to install via:
sudo pip install MySQL-python
I get an error stating:
raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found
I've already tried running:
export PATH=$PATH:/usr/local/mysql/bin
but that didn't seem to help, as I ran the installation command again and it still failed.
Any ideas?
Please note I'm not in a virtualenv.
-
martin-martin almost 6 yearsMy
libs
inside ofmysql_config
was already as described in "Change to" section. However, adding the the PATH toprivate/etc
helped to allow the global install ofmysqlclient
that was failing before. -
Neil C. Obremski over 4 yearsI saw your answer after finding the binaries on disk by running
sudo lsof -i :3306
to see the PID of the active MySQL process and then runningsudo -P <pid>
on that to see its open files. This came up with/usr/local/mysql-8.0.18-macos10.14-x86_64/bin
which I added to$PATH
and voila! -
Yagimutsu over 4 yearsThank you! I tried so many things and your method worked for me.
-
Umang about 3 yearsI got it installed globally but still not able to install on my virtual environment. Looks like some mysql_config error. Any ideas on how to install it locally?
-
supreme Pooba almost 2 yearsit is actually
brew install mysql-client