在osx 10.8上intall mysql-python时找不到"my_config.h"文件

nin*_*sun 42 mysql-python

当我想在osx 10.8上安装mysql-python时遇到这个问题,它显示错误,找不到'my_config.h'文件.任何人都可以帮助我,我非常感谢您的贡献,谢谢.

以下是我的运行代码:

sudo easy_install mysql-python
Password:
Searching for mysql-python
Reading http://pypi.python.org/simple/mysql-python/
Reading http://sourceforge.net/projects/mysql-python/
Reading http://sourceforge.net/projects/mysql-python
Best match: MySQL-python 1.2.3
Downloading http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.3.tar.gz#md5=215eddb6d853f6f4be5b4afc4154292f
Processing MySQL-python-1.2.3.tar.gz
Running MySQL-python-1.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-UoZlf7/MySQL-python-1.2.3/egg-dist-tmp-phaQqE
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
clang: warning: argument unused during compilation: '-mno-fused-madd'
_mysql.c:36:10: fatal error: 'my_config.h' file not found
#include "my_config.h"
         ^
1 error generated.
error: Setup script exited with error: command 'clang' failed with exit status 1
ninjaiimac:MySQL-python-1.2.3 sunninjaisun$ 
Run Code Online (Sandbox Code Playgroud)

Jof*_*sey 81

brew install mysql
brew unlink mysql
brew install mysql-connector-c
sed -i -e 's/libs="$libs -l "/libs="$libs -lmysqlclient -lssl -lcrypto"/g' /usr/local/bin/mysql_config
pip install MySQL-python
brew unlink mysql-connector-c
brew link --overwrite mysql
Run Code Online (Sandbox Code Playgroud)

  • 根本不起作用。它会在“pip install MySQL-python”上引发相同的错误 (9认同)
  • 该答案的说明应为:“默认的mysql程序包不附带mysql头文件,但mysql-connector-c程序包附带。问题是,它们覆盖了mysql命令,因此我们首先必须取消链接默认程序包,然后添加mysql-connector -c一个,然后再次重新链接mysql。 (5认同)
  • 这些步骤对我有用.macOS 10.13.6.python 2.7.15. (4认同)
  • 我必须将“ pip install”命令更改为“ LDFLAGS = -L / usr / local / opt / openssl / lib pip install MySQL-python”,以使其在Mojave上起作用。 (4认同)
  • 这对我来说就像在macOS Mojave(10.14.1)和python 2.7.10上一样.谢谢!! (2认同)
  • mysql-connector-c 不再可用,它已被 mysql-client 取代。我应该怎么办? (2认同)

om2*_*0de 36

适用于macOS High Sierra:

如果你还没有安装mysql: brew install mysql

brew unlink mysql
brew install mysql-connector-c
brew link --overwrite mysql
pip install MySQL-python
Run Code Online (Sandbox Code Playgroud)


DàC*_*hún 28

请试试:

brew install mysql-connector-c 
pip install MySQL-python
Run Code Online (Sandbox Code Playgroud)

  • 没有为我工作,我不得不在安装mysql-connector-c之前`brew unlink mysql`,但是然后`pip install MySQL-python`给了'命令'python setup.py egg_info"失败,错误代码1在/ private在/ var /文件夹/平方英尺/ gzfw30z10xd6lk3zb7p9q73h0000gn/T/PIP安装-VOZP1p/MySQL的 - 蟒蛇/" (14认同)
  • 它对我来说就像一个魅力!谢谢!! (2认同)

Jak*_*ake 9

我的问题是我使用的是MAMP版本的mysql,它不包含dev头文件.我下载了正式版的dmg,并立即运行.

  • 携带两个MySQL感觉有点......蹩脚.我希望有更好的工作 (2认同)
  • 只需更改为postgresql即可.我很高兴我做到了. (2认同)
  • 好吧,也许MAMP人可以提供dev头作为可选下载,以使这样的事情更容易.也许更好的选择是将PHP和Apache与MySQL一起安装并卸载MAMP.但总的来说我同意:PostgreSQL很可爱. (2认同)

Ale*_*x W 9

我曾经brew在Mac OS 10.14.2上安装了所有软件。

virtualenv在Mojave 上的虚拟环境()内时,其他答案对我不起作用。我按照Jofsey的指示进行操作,但出现错误:

#        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
Run Code Online (Sandbox Code Playgroud)

因此,在我运行了这些命令之后,我将其作为最终命令运行了,并且有效:

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"
Run Code Online (Sandbox Code Playgroud)

编辑:

我在GitHub上找到了另一个解决方案,假设您已经运行了brew install openssl(这避免了使用CLI参数,并且可以防止将来出现SSL库错误):

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
Run Code Online (Sandbox Code Playgroud)

您可以将以上内容放入~/.bash_profile文件中然后运行,source ~/.bash_profile或者如果它是虚拟环境,则可以找到一种方法在虚拟环境外壳中运行导出,并使用来检查虚拟环境CLI中的值echo $LIBRARY_PATH。一旦$LIBRARY_PATH设置,你会不会继续看到这些SSL库错误。

  • 我在同一条船上。这是Mojave上唯一可行的解​​决方案:) (3认同)

小智 9

我检查了include文件夹都mysqlmysql-connector-c通过自制软件安装,惊讶地看到有一个名为没有文件my_config.h。因此,我认为现有的高票答案已不能解决问题。

这是我的解决方案mysql 8.0.19。我将mysql.h文件复制到include/我安装的文件夹下mysql-connector-c并将其保存my_config.h在同一文件夹下。然后我按照下面的高票解决方案并成功安装了mysql-python 1.2.5.

brew install mysql
brew unlink mysql
brew install mysql-connector-c   # modify the include/ folder after installing the package
sed -i -e 's/libs="$libs -l "/libs="$libs -lmysqlclient -lssl -lcrypto"/g' /usr/local/Cellar/mysql/8.0.19/bin/mysql_config
pip install MySQL-python
brew unlink mysql-connector-c
brew link --overwrite mysql
Run Code Online (Sandbox Code Playgroud)

目前,我只知道它可以成功安装软件包,但我不确定它是否是一个安全的解决方案。

实际上,mysql-python是一个相当老的包(最新版本是 6 年前的),我推荐其他包在 python 中与 mysql 交互(例如mysql-connector-python)。


kom*_*ten 6

在 Macos 上,我按照gethue上的安装说明进行操作。然后我从Oracle下载了 my_config.h ,将该文件放在 /usr/local/include 中,安装得以继续。但停在一个不相关的丢失文件处。

Oracle 的链接已更新为较新版本的 MySQL 8.0.26。

  • 将头文件放在“/usr/local/include”中对我有用 (2认同)

aka*_*rca 5

这在 macOS Catalina 10.15.7 和 python 2.7 上对我有用

brew install mysql@5.7
brew link --force mysql@5.7
PATH="/usr/local/opt/mysql@5.7/bin:$PATH" LDFLAGS="-L/usr/local/Cellar/mysql@5.7/5.7.29/lib -L/usr/local/Cellar/openssl@1.1/1.1.1d/lib" CPPFLAGS="-I/usr/local/Cellar/mysql@5.7/5.7.29/include -I/usr/local/Cellar/openssl@1.1/1.1.1d/include" pip install mysql-python
Run Code Online (Sandbox Code Playgroud)