0

Hi all so i'm attempting to run django on my local machine to connect to a docker container running mysql but keep getting an error when attempting to install mysqlclient via pip. First i got this error when attempting to 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/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup_posix.py", line 26, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    OSError: mysql_config not found

Then i went ahead and installed mysql-connector-cvia brew. I reran pip install mysqlclient and now i get this error:

Collecting mysqlclient
  Using cached mysqlclient-1.3.12.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 54, in get_config
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 12, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

Has anyone come across the error when attempting to run django on localmachine while connecting to mysql running in a docker container?

EI-01
  • 1,075
  • 3
  • 24
  • 42
  • remove `mysqlclient-1.3.12.tar.gz` file from `/var/cache/apt/archieves` – Avinash Raj Oct 04 '17 at 07:05
  • @AvinashRaj but im running mysql in docker. Do i need to install mysql on my localhost to run django app from local machine to connect to the docker container running mysql – EI-01 Oct 04 '17 at 16:54

1 Answers1

0

As you're using macOS, try this code below:

brew remove mysql-connector-c
brew install mysql
pip3 install mysqlclient

This will work for you.

Beomi
  • 1,697
  • 16
  • 18
  • but im running mysql in docker. Do i need to install mysql on my localhost to run django app from local machine to connect to the docker container running mysql – EI-01 Oct 04 '17 at 16:54
  • Trust me, this is the `simplist` way to do. `mysqlclient` python packages depends on C lib in `mysql` package, so this way is the `simplist` way to do. – Beomi Oct 04 '17 at 16:57
  • Sure there are more options like https://stackoverflow.com/questions/30990488/how-do-i-install-command-line-mysql-client-on-mac/35338119 , but I recommend the best way for you. And one thing more, it doesn't mean `running mysql server` when you do `brew install mysql` :) – Beomi Oct 04 '17 at 16:59
  • thanks but now im running into an error as i tried your suggestion – EI-01 Oct 05 '17 at 04:23
  • the error i receive is `ld: library not found for -lssl clang: error: linker command failed with exit code 1` – EI-01 Oct 05 '17 at 04:38