0

I just started learning Python using Django and I just seemed to be stuck at the same place for 3 days, every time I try to run the following command in my terminal using Pycharm (Yep, I am using a Mac) I get the below error:

Command: pip install mysqlclient

Error:

Collecting mysqlclient
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3z/_xzmzzh90z9dj90cb70p3q0c0000gn/T/pip-build-c7mudszc/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3z/_xzmzzh90z9dj90cb70p3q0c0000gn/T/pip-build-c7mudszc/mysqlclient/setup_posix.py", line 44, in get_config
(venv) Mervins-MacBook-Pro:untitled mervinkobola$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3z/_xzmzzh90z9dj90cb70p3q0c0000gn/T/pip-build-w_jamo3b/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3z/_xzmzzh90z9dj90cb70p3q0c0000gn/T/pip-build-w_jamo3b/mysqlclient/setup_posix.py", line 44, in get_config
(venv) Mervins-MacBook-Pro:untitled mervinkobola$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3z/_xzmzzh90z9dj90cb70p3q0c0000gn/T/pip-build-xefx4qk7/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3z/_xzmzzh90z9dj90cb70p3q0c0000gn/T/pip-build-xefx4qk7/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/private/var/folders/3z/_xzmzzh90z9dj90cb70p3q0c0000gn/T/pip-build-xefx4qk7/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3z/_xzmzzh90z9dj90cb70p3q0c0000gn/T/pip-build-xefx4qk7/mysqlclient/

Please help me understand whats going on and how I can solve it. Above all I can't seem to run the following :

python manage.py migrate (as I haven't installed mysqlclient)

Thank you in advance for your assistance.

4
  • You might find this answer useful (ignore the pip install MySQL-Python and stick with pip install mysqlclient). Note that if you're just learning Python and Django, you may find it easier to stick with sqlite3 instead of MySQL. Commented Jan 23, 2018 at 13:00
  • Thank you for your response, well I've already used MySQL, and it seems to connecting successfully, I just cant run the following command "python manage.py migrate" for my tables, it will ask me if I've installed mysqlclient (even when I go to my virtual env and try there without using my command, it still gives an error), is there pehaps a quick fix, and this is on mac using pycharm? Commented Jan 23, 2018 at 13:09
  • The quickest fix is to use sqlite3, which doesn't require any additional packages to be installed. If you want to use Django with MySQL, then you need to install mysqlclient in your virtual environment. The answer I linked to has some suggestions for installing it on a Mac which will hopefully help, but I'm afraid I don't have any other suggestions. Commented Jan 23, 2018 at 13:28
  • Thank you very much, I will use mysqlite 3, hopefully this will help. Commented Jan 23, 2018 at 13:31

1 Answer 1

3

Sometimes the variable mysql_config is set in the Terminal but not in PyCharm so this is why you're getting this error.

The solution is:

  1. run the PyCharm from the terminal with this command:

    /Applications/PyCharm\ CE.app/Contents/MacOS/pycharm

  2. After that (in PyCharm) install the packages you need (probably they are in your requirements.txt, for example the mysqlclient),

  3. Close the program and re-open

  4. Now it should have all the packages installed properly

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.