“my_config.h” file not found when install mysql-python on osx 10.8

前端 未结 12 1969
礼貌的吻别
礼貌的吻别 2020-12-07 11:06

I face this problem when I want to install mysql-python on osx 10.8, it show error with \'my_config.h\' file not found.

Below is my running code:

sud         


        
相关标签:
12条回答
  • 2020-12-07 11:40

    Works well on macOS High Sierra:

    If you haven't already installed mysql: brew install mysql

    brew unlink mysql
    brew install mysql-connector-c
    brew link --overwrite mysql
    pip install MySQL-python
    
    0 讨论(0)
  • 2020-12-07 11:43

    I used brew to install everything on Mac OS 10.14.2.

    The other answers weren't working for me, when inside of a virtual environment (virtualenv) on Mojave. I followed Jofsey's instructions but got errors:

    #        define SIZEOF_LONG             4
                        ^
        In file included from _mysql.c:44:
        /usr/local/include/my_config.h:179:9: warning: 'SIZEOF_TIME_T' macro redefined [-Wmacro-redefined]
        #define SIZEOF_TIME_T    8
                ^
        /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:57:17: note: previous definition is here
        #        define SIZEOF_TIME_T           4
                        ^
        2 warnings generated.
        _mysql.c:287:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                        cmd_argc = PySequence_Size(cmd_args);
                                 ~ ^~~~~~~~~~~~~~~~~~~~~~~~~
        _mysql.c:317:12: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                        groupc = PySequence_Size(groups);
                               ~ ^~~~~~~~~~~~~~~~~~~~~~~
        _mysql.c:470:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                                int j, n2=PySequence_Size(fun);
                                       ~~ ^~~~~~~~~~~~~~~~~~~~
        _mysql.c:1127:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                        len = mysql_real_escape_string(&(self->connection), out, in, size);
                            ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        _mysql.c:1129:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                        len = mysql_escape_string(out, in, size);
                            ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        _mysql.c:1168:9: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                size = PyString_GET_SIZE(s);
                     ~ ^~~~~~~~~~~~~~~~~~~~
        /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/stringobject.h:92:32: note: expanded from macro 'PyString_GET_SIZE'
        #define PyString_GET_SIZE(op)  Py_SIZE(op)
                                       ^~~~~~~~~~~
        /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:116:56: note: expanded from macro 'Py_SIZE'
        #define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)
                                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
        _mysql.c:1178:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                        len = mysql_real_escape_string(&(self->connection), out+1, in, size);
                            ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        _mysql.c:1180:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                        len = mysql_escape_string(out+1, in, size);
                            ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        _mysql.c:1274:11: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                if ((n = PyObject_Length(o)) == -1) goto error;
                       ~ ^~~~~~~~~~~~~~~~~~
        /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/abstract.h:434:25: note: expanded from macro 'PyObject_Length'
        #define PyObject_Length PyObject_Size
                                ^
        _mysql.c:1466:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                len = strlen(buf);
                                    ~ ^~~~~~~~~~~
        _mysql.c:1468:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                len = strlen(buf);
                                    ~ ^~~~~~~~~~~
        _mysql.c:1504:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                        len = strlen(buf);
                                            ~ ^~~~~~~~~~~
        _mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                        len = strlen(buf);
                                            ~ ^~~~~~~~~~~
        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-connector-c/6.1.11/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
    

    So, after I ran those commands, I ran this as the final command and it worked:

    sudo pip install MySQL-Python --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" --global-option="-L/usr/local/opt/openssl/lib"
    

    Edit:

    Another solution I found on GitHub, assuming you've already run brew install openssl (which avoids the need for CLI parameters and will prevent future SSL library errors):

    export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
    

    You can put the above in your ~/.bash_profile file and then run source ~/.bash_profile or if it's a virtual environment, you can find a way to run the export in the virtual environment shell and check the value in the virtual environment CLI with echo $LIBRARY_PATH. Once the $LIBRARY_PATH is set, you won't keep seeing these SSL library errors.

    0 讨论(0)
  • 2020-12-07 11:46

    What worked for me in Nov 2020 for Catalina 10.15.7 and Python 2.7.16 was a combination of two answers:

    Step 1: https://stackoverflow.com/a/61800247/14686220

    However, instead of simply copying mysql.h file as my_config.h in the include/ directory (which can be dangerous), I copied the my_config.h file from the official MySQL docs

    Step 2: https://stackoverflow.com/a/54079052/14686220

    0 讨论(0)
  • 2020-12-07 11:49

    As mentioned before, you need the dev headers for MySQL, which don't come with MAMP by default. Rather than using two instances of MySQL, it's possible to add the headers to the MAMP version. There are good instructions for doing so here: http://dreamconception.com/tech/how-to-install-mysqldb-mysql-python-on-mamp/

    Make sure not to just copy-paste all the commands, they're a bit out of date so you'll need to change the version numbers in some of them.

    I'm using OS X 10.9 and python 2.7, and everything works.

    0 讨论(0)
  • 2020-12-07 11:49

    On macos I followed the installation instructions at gethue. Then I downloaded my_config.h from Oracle, placed the file in /usr/local/include, and the installation was able to continue. But stopped at an unrelated missing file.

    0 讨论(0)
  • 2020-12-07 11:51

    please try:

    brew install mysql-connector-c 
    pip install MySQL-python
    
    0 讨论(0)
提交回复
热议问题