411👍
Ok, well, first of all, let me check if I am on the same page as you:
- You installed python
- You did
brew install mysql
- You did
export PATH=$PATH:/usr/local/mysql/bin
- And finally, you did
pip install MySQL-Python
(orpip3 install mysqlclient
if using python 3)
If you did all those steps in the same order, and you still got an error, read on to the end, if, however, you did not follow these exact steps try, following them from the very beginning.
So, you followed the steps, and you’re still geting an error, well, there are a few things you could try:
-
Try running
which mysql_config
from bash. It probably won’t be found. That’s why the build isn’t finding it either. Try runninglocate mysql_config
and see if anything comes back. The path to this binary needs to be either in your shell’s $PATH environment variable, or it needs to be explicitly in the setup.py file for the module assuming it’s looking in some specific place for that file. -
Instead of using MySQL-Python, try using ‘mysql-connector-python’, it can be installed using
pip install mysql-connector-python
. More information on this can be found here and here. -
Manually find the location of ‘mysql/bin’, ‘mysql_config’, and ‘MySQL-Python’, and add all these to the $PATH environment variable.
-
If all above steps fail, then you could try installing ‘mysql’ using MacPorts, in which case the file ‘mysql_config’ would actually be called ‘mysql_config5’, and in this case, you would have to do this after installing:
export PATH=$PATH:/opt/local/lib/mysql5/bin
. You can find more details here.
Note1: I’ve seen some people saying that installing python-dev
and libmysqlclient-dev
also helped, however I do not know if these packages are available on Mac OS.
Note2: Also, make sure to try running the commands as root.
I got my answers from (besides my brain) these places (maybe you could have a look at them, to see if it would help): 1, 2, 3, 4.
I hoped I helped, and would be happy to know if any of this worked, or not. Good luck.
14👍
If you don’t want to install full mysql, we can fix this by just installing mysql-client
brew install mysql-client
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
.
- [Django]-Django 1.5 custom User model error. "Manager isn't available; User has been swapped"
- [Django]-How to add new languages into Django? My language "Uyghur" or "Uighur" is not supported in Django
- [Django]-How to set and get cookies in Django?
10👍
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.
- [Django]-Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet
- [Django]-Django Rest Framework – Authentication credentials were not provided
- [Django]-Programmatically saving image to Django ImageField
5👍
If you have installed mysql using Homebrew by specifying a version then mysql_config would be present here. – /usr/local/Cellar/mysql@5.6/5.6.47/bin
you can find the path of the sql bin by using ls command in /usr/local/ directory
/usr/local/Cellar/mysql@5.6/5.6.47/bin
Add the path to bash profile like this.
nano ~/.bash_profile
export PATH="/usr/local/Cellar/mysql@5.6/5.6.47/bin:$PATH"
- [Django]-How to server HTTP/2 Protocol with django
- [Django]-How do I create a slug in Django?
- [Django]-How do I integrate Ajax with Django applications?
4👍
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"
- [Django]-Referencing multiple submit buttons in django
- [Django]-How to use pdb.set_trace() in a Django unittest?
- [Django]-Django Rest Framework – Updating a foreign key
3👍
Also this happens when I was installing mysqlclient,
$ pip install mysqlclient
As user3429036 said,
$ brew install mysql
- [Django]-How can I serialize a queryset from an unrelated model as a nested serializer?
- [Django]-How to add multiple objects to ManyToMany relationship at once in Django ?
- [Django]-Django datetime issues (default=datetime.now())
2👍
This answer is for MacOS users who did not install from brew
but rather from the official .dmg/.pkg
. That installer fails to edit your PATH
, causing things to break out of the box:
- All MySQL commands like
mysql
,mysqladmin
,mysql_config
, etc cannot be found, and as a result: - the “MySQL Preference Pane” fails to appear in System Preferences, and
- you cannot install any API that communicates with MySQL, including
mysqlclient
What you have to do is appending the MySQL bin
folder (typically /usr/local/mysql/bin
in your PATH
by adding this line in your ~/.bash_profile
file:
export PATH="/usr/local/mysql/bin/:$PATH"
You should then reload your ~/.bash_profile
for the change to take effect in your current Terminal session:
source ~/.bash_profile
Before installing mysqlclient
, however, you need to accept the XcodeBuild license:
sudo xcodebuild -license
Follow their directions to sign away your family, after which you should be able to install mysqlclient
without issue:
pip install mysqlclient
After installing that, you must do one more thing to fix a runtime bug that ships with MySQL (Dynamic Library libmysqlclient.dylib
not found), by adding this line to your system dynamic libraries path:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH
- [Django]-Warning: Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'
- [Django]-Can I access constants in settings.py from templates in Django?
- [Django]-How do I remove Label text in Django generated form?
2👍
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!
- [Django]-Error: No module named staticfiles
- [Django]-How to get Django and ReactJS to work together?
- [Django]-Django: Reference to an outer query may only be used in a subquery
0👍
The problem in my case was that I was running the command inside a python virtual environment and it didn’t had the path to /usr/local/mysql/bin though I have put it in the .bash_profile file. Just exporting the path in the virtual env worked for me.
For your info sql_config resides inside bin directory.
- [Django]-How to set and get cookies in Django?
- [Django]-How to force Django models to be released from memory
- [Django]-Why is logged_out.html not overriding in django registration?
-1👍
Install brew or apt-get is also not easy for me so I downloaded mysql via: https://dev.mysql.com/downloads/connector/python/, installed it. So I can find mysql_config int this directory: /usr/local/mysql/bin
the next step is:
- export PATH=$PATH:/usr/local/mysql/bin
- pip install MySQL-python==1.2.5
- [Django]-Django create userprofile if does not exist
- [Django]-Why is __init__ module in django project loaded twice
- [Django]-*_set attributes on Django Models