2

I am new to Python, coming from Java and JS background,
I've installed Python and Pip in my local machine,
I am trying to learn Django, using MySQL,
But I am unable to install the mysqlclient using pip,
I used the following command to do so -

pip install mysqlclient

It's giving the following error -

Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/
    Complete output (12 lines):
    /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 1, in <module>
      File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup.py", line 16, in <module>
        metadata, options = get_config()
      File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup_posix.py", line 61, in get_config
        libs = mysql_config("libs")
      File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    OSError: mysql_config not found
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Screenshot -

enter image description here

damon
  • 14,485
  • 14
  • 56
  • 75
Dev1ce
  • 5,390
  • 17
  • 90
  • 150
  • 2
    Try,`pip install pymysql`. https://pypi.org/project/PyMySQL/ – CodeIt Aug 25 '19 at 06:01
  • Hi, It seems it got installed, but then what's the difference between `mysqlclient` and `pymysql`? Will it cause config issues later on? – Dev1ce Aug 25 '19 at 06:10
  • 2
    `pymysql` is a pure python MySQL client whereas `mysqlclient` requires `mysql-connector-c`. If you like to read me check this [answer](https://stackoverflow.com/a/46396881/3091398). – CodeIt Aug 25 '19 at 06:13
  • so no code changes right? I can use MySql as usual? The only difference here was, we used different client yea? – Dev1ce Aug 25 '19 at 06:15
  • No much difference, you can use it as usual. – CodeIt Aug 25 '19 at 06:17

2 Answers2

3

mysqlclient requires additional c libraires.
For linux (Debian):
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
For Mac:
$ brew install mysql
Further reading at the home page

tomasz74
  • 16,031
  • 10
  • 37
  • 51
2

I am solve error following process

Python 3.8.0

First install in Homebraw type following command. type this command in terminal

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install mariadb-connector-c

pip install mysqlclient

more issues follow this tutorial https://medium.com/@MrWeeble/homebrew-on-mac-and-pythons-mysqlclient-ea44fa300e70