0

I have been trying to install python-MySQLdb on mac and I keep getting error. I have tried so many alternatives to pass that error.

sudo PATH=/usr/local/Cellar/mysql/bin/:$PATH pip install mysql-python
Password:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
The directory '/Users/zuhairhallak/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/zuhairhallak/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting mysql-python
  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 2.6MB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-install-RtF2js/mysql-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 53, in get_config
        libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
      File "setup_posix.py", line 8, 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/tmp/pip-install-RtF2js/mysql-python/

I have also ran sudo -H pip install mysql-python and I got different error

13 warnings generated. cc -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.14-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql/8.0.15/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-intel-2.7/_mysql.so ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'cc' failed with exit status 1


Failed building wheel for mysql-python Running setup.py clean for mysql-python Failed to build mysql-python Installing collected packages: mysql-python Running setup.py install for mysql-python ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/private/tmp/pip-install-3A8kOd/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /private/tmp/pip-record-TUb4up/install-record.txt --single-version-externally-managed --compile

  • 3
    Possible duplicate of ['pip install MySQL-python' fails with 'IndexError'](https://stackoverflow.com/questions/43543483/pip-install-mysql-python-fails-with-indexerror) – Ardweaden Mar 27 '19 at 19:58
  • its not duplicate question but i kept having different errors for each alternative solution i try. Fixed my problem though –  Mar 28 '19 at 02:01

2 Answers2

0

Please try

brew install mysql
sudo -H pip install mysql-python
Damiano
  • 71
  • 1
  • 7
  • 1
    Could you add some more detail saying what's wrong and how this fixes it? It'll help understanding for the OP and future readers. – squaregoldfish Mar 27 '19 at 20:47
  • Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-3A8kOd/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-TUb4up/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-3A8kOd/mysql-python/ –  Mar 27 '19 at 23:58
  • I got another error After running sudo -H pip install mysql-python –  Mar 27 '19 at 23:59
0

I went to the mysql_config file and opened it up

vi mysql_config

This was correct.

Create options:
Libs = "- L $ pkglibdir"
Libs = "$ libs -lmysqlclient -lssl -lcrypto"

ran this command in terminal 1. export LDFLAGS="-L/usr/local/opt/openssl/lib" 2. export CPPFLAGS="-I/usr/local/opt/openssl/include" 3. pip install mysql-python