Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python setup.py egg_info mysqlclient

Trying to install mysqlclient using pip3 on Python 3.6.0

$ pip3 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.10.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/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/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/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 12, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/

Already did

brew install mysql-connector-c

But still getting this error

like image 506
Denis Ostrovsky Avatar asked May 02 '17 14:05

Denis Ostrovsky


People also ask

How to fix python egg_info failed with error code 1?

The command python setup.py egg_info failed with error code 1 can also be caused by the pip itself. If you are using an old version of pip, we recommend you update it to the latest version. To do so, you just need to run python -m pip install -U pip in the elevated Command Prompt.

How to install MySQL client in Python 3?

You may need to install the Python 3 and MySQL development headers and libraries like so: Then you can install mysqlclient via pip now: mysqlclient uses mysql_config or mariadb_config by default for finding compiler/linker flags. You can use MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variables to customize compiler/linker options.

How to install mysqlclient using pip?

Then you can install mysqlclient via pip now: mysqlclient uses mysql_config or mariadb_config by default for finding compiler/linker flags. You can use MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variables to customize compiler/linker options. Download the file for your platform.

How to fix Pip error code 1 in Python?

To do so, you just need to run python -m pip install -U pip in the elevated Command Prompt. Tip: If this command can’t fix the pip error code 1, you can try running the python3 -m pip3 install -U pip command.


3 Answers

This worked for me:

  1. brew install mysql-connector-c

  2. edit mysql_config (locate it: which mysql_config)

correct this in mysql_config:

# Create options 
libs="-L$pkglibdir"
libs="$libs -l "

It shoud be:

# Create options 
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
  1. brew info openssl
  2. and finally pip3 install mysqlclient
like image 61
kvasnicaj Avatar answered Oct 19 '22 19:10

kvasnicaj


I resolved this installing libmysqlclient-dev first:

sudo apt-get install libmysqlclient-dev

Hope it works for you.

like image 34
yosbel Avatar answered Oct 19 '22 21:10

yosbel


After extensive troubleshooting, I found that the brew install mysql-connector-c just does not work.

The problem stems from the system not being able to identify that mysql_config is installed (which is what mysql-connector-c essentially does). Homebrew's method (open for argument) of installing the mysql-connector-c in its /Cellar/ and creating a symlink to the /usr/local/bin/ directory seems to be causing problems as Python tries to follow the symlink.

To resolve the issue I performed the following:

  1. brew uninstall mysql-connector-c
  2. download/install MacOS X MySQL Connector/C from Oracle's MySQL site
    • note: just download the .dmg, no need to be complicated here...
  3. restart MacOS Terminal (or iTerm2) for good measure
  4. which mysql_config

    • you should see the correct path /usr/local/bin/mysql/bin/mysql_config
  5. activate virtualenv (if applicable)

  6. pip install mysqlclient

There may be other ways to still use Homebrew, but this was the most straightforward solution I found.

Note that the mysqlclient GitHub README.md also states that the C-developer headers for Python3 are needed. I assume that mysql-connector-c includes those; however, should you run into more issues, you might also install the Xcode Developer CI Tools for good measure.

xcode-select --install

They include the C compiler and other developer utilities from Apple. Read more here.

like image 30
Israel Flores Avatar answered Oct 19 '22 20:10

Israel Flores