Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

command 'cc' failed with exit status 1 on OSX High Sierra

I'm trying to run on Mac Os high Sierra

pip install MySQL-python

But I'm getting

error: command 'cc' failed with exit status 1

I already tried the solution on this topic, but it didn't work.

This is the full error message

The directory '/Users/filipeferminiano/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/filipeferminiano/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 289kB/s 
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python ... error
    Complete output from command /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-8I1X5u/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-z5HohX/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13-intel-2.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.13-intel-2.7
    creating build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    creating build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.13-intel-2.7
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/8.0.11/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.13-intel-2.7/_mysql.o
    _mysql.c:44:10: fatal error: 'my_config.h' file not found
    #include "my_config.h"
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'cc' failed with exit status 1

    ----------------------------------------
Command "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-8I1X5u/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-z5HohX/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-8I1X5u/MySQL-python/

This is the python

which python
/usr/bin/python

and this is the pip I'm using

which pip
/usr/local/bin/pip
like image 921
Filipe Ferminiano Avatar asked Jul 14 '18 20:07

Filipe Ferminiano


2 Answers

First, are you sure you want to use MySQL-python? This is a mostly-dead project that's been semi-maintained for legacy support for the past half decade, and doesn't even work with current versions of MySQL. It wants 5.0 or maybe 5.1; the current version is 8.0, and even the current legacy version is 5.7.


Other options include:

  • mysql-connector, aka MySQLConnector/Python: This is the officially supported library, from MySQL/Oracle. It can be a bit slow, which doesn't matter for most projects, but it can sometimes. It also has a different API (although if you stick to DB-API 2 methods, the only difference is the connect call; beyond that it should just be low-level stuff that's different).
  • mysqlclient: This is the package that Django and some other frameworks use. It's an updated fork of MySQL-Python (with a few things from its abandoned successor, moist). It can even be configured to install itself as MySQLdb, the same name used by MySQL-python.
  • PyMySQL: A third-party package built to be as compatible as possible with the old MySQL-python but simpler and easier to maintain, and install.
  • cmysql, a fork of PyMySQL that's only slightly harder to install, but should be faster than it, or than mysql-connector.

Some linux distros—including, IIRC, recent versions of Ubuntu—provide a package named python-MySQLdb or similar that is not actually MySQL-python, but instead mysqlclient built with the install-as-MySQLdb option. So, if the only reason that you're trying to use MySQL-python is that it's what you were using on some Ubuntu box, it's probably not what you were using, and therefore not what you want.

Some of these alternative also require MySQL (specifically, MySQLConnector/C, aka libmysqlclient, and its development libraries), some don't—but they're all compatible with current versions. (Although there are some notes on 8.0 crypto changes in the docs for PyMySQL and cmysql, which you might want to read if you use 8.0.)


Anyway, if you really want MySQL-python, then you will need to install MySQL in a 5.x version. The INSTALL points you to MySQL downloads.

If you want 5.0 or 5.1, you will have to dig through the Downloads folder at one of the mirrors to find a source package and follow the instructions to build and install it, since there are no binary installers that work on current Macs.

If you want later 5.x versions—which, remember, are not supported by MySQL-python, but they might work—Oracle is still providing Mac binary installers for those. If you can't find them in the main downloads section, the mirrors' Downloads folder will have them. As of right now, 5.6 and 5.7 have binary installer packages that end with -macos10.13-x86_64.dmg.

However, you might be happier installing it with Homebrew. Follow the instructions on that page to install brew, then to use it to:

brew install [email protected]

MySQL-python also requires OpenSSL libraries, and Apple deliberately hides the ones used by the OS to prevent people from accidentally building code against an old version and not getting security updates. The newer libraries should all know how to handle this, but MySQL-python does not. The easiest way to install a usable OpenSSL is with Homebrew again:

brew install openssl

But don't just run that command and close the window. Read the output, because you have to do all the stuff it says if you want MySQL-python to build.

like image 65
abarnert Avatar answered Sep 20 '22 03:09

abarnert


My issue was that I was using MySql Version 8.0.12. As soon as I downgraded to MySQL 5.7, it was installed perfectly. I used the following to delete the version 8 by following: https://gist.github.com/vitorbritto/0555879fe4414d18569d

The gist of the above was:

  1. Check for MySQL processes with: ps -ax | grep mysql
  2. Stop and kill any MySQL processes
  3. brew remove mysql
  4. brew cleanup
  5. launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  6. sudo rm /usr/local/mysql
  7. sudo rm -rf /usr/local/var/mysql
  8. sudo rm -rf /usr/local/mysql*
  9. sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  10. sudo rm -rf /Library/StartupItems/MySQLCOM
  11. sudo rm -rf /Library/PreferencePanes/My*
  12. rm -rf ~/Library/PreferencePanes/My*
  13. sudo rm -rf /Library/Receipts/mysql*
  14. sudo rm -rf /Library/Receipts/MySQL*
  15. sudo rm -rf /private/var/db/receipts/mysql
  16. Restart your computer just to ensure any MySQL processes are killed
  17. install mysql using brew: brew install [email protected]
  18. Finally, pip install mysql-python
like image 35
Ashwin_Mathew Avatar answered Sep 17 '22 03:09

Ashwin_Mathew