当我想在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$
答案 0 :(得分:65)
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
答案 1 :(得分:27)
请尝试:
brew install mysql-connector-c
pip install MySQL-python
答案 2 :(得分:23)
在macOS High Sierra上运行良好:
如果尚未安装mysql:brew install mysql
brew unlink mysql
brew install mysql-connector-c
brew link --overwrite mysql
pip install MySQL-python
答案 3 :(得分:9)
我的问题是我使用的是MAMP版本的mysql,它不包含dev头文件。我下载了正式版的dmg,并立即运行。
答案 4 :(得分:8)
我检查了ice
文件夹中是否有自制软件安装的include
和mysql
,很惊讶地发现没有名为mysql-connector-c
的文件。因此,我认为现有的高投票答案不再能够解决问题。
这是我对my_config.h
的解决方案。我将mysql 8.0.19
文件复制到已安装的mysql.h
的{{1}}文件夹下,并将其另存为include/
在同一文件夹下。然后,我按照如下所示的投票解决方案,成功安装了mysql-connector-c
。
my_config.h
目前,我只知道它可以成功安装该软件包,但是我不确定这是否是安全的解决方案。
实际上,mysql-python 1.2.5
是一个非常古老的软件包(最新版本是6年前),我建议使用其他软件包与python中的mysql交互(例如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
)。
答案 5 :(得分:2)
2020年11月, Catalina 10.15.7 和 Python 2.7.16 对我有用的是两个答案的组合:
第1步:https://stackoverflow.com/a/61800247/14686220
但是,我不是简单地将mysql.h
文件复制为my_config.h
目录中的include/
(这可能很危险),而是从{{3 }}
答案 6 :(得分:1)
我使用brew
在Mac OS 10.14.2上安装了所有程序。
在Mojave上的虚拟环境(virtualenv
)内时,其他答案对我不起作用。我按照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
因此,在我运行了这些命令之后,我将其作为最终命令运行,并且有效:
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"
答案 7 :(得分:1)
我从答案中一直尝试,这对我不起作用。
只需从以下位置下载mysql
https://dev.mysql.com/downloads/mysql/
并安装在您的Mac中。 请勿使用 brew install mysql
安装MySQL-python
pip install MySQL-python
每件事都做完
答案 8 :(得分:1)
这在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
答案 9 :(得分:0)
如前所述,您需要MySQL的dev头文件,默认情况下不包含MAMP。 不是使用MySQL的两个实例,而是可以将标头添加到MAMP版本中。 这里有很好的指示: http://dreamconception.com/tech/how-to-install-mysqldb-mysql-python-on-mamp/
请确保不要复制粘贴所有命令,它们有点过时,因此您需要更改其中某些命令的版本号。
我正在使用OS X 10.9和python 2.7,一切正常。
答案 10 :(得分:0)
在macOS上,我按照gethue上的安装说明进行操作。然后,我从Oracle下载了my_config.h,将该文件放在/ usr / local / include中,安装得以继续。但是停在一个不相关的丢失文件上。
答案 11 :(得分:0)
在macOS 10.15上,只要您的项目与PyMySQL 1.3.11或更高版本兼容,以下内容便可以解决此问题:
brew install mariadb-connector-c
pip install MySQL-python
参考:https://github.com/PyMySQL/mysqlclient-python/blob/master/HISTORY.rst
答案 12 :(得分:0)
使用conda
代替pip
在macOS Catalina 10.15.5上为我解决了此问题
conda install mysql-python