本文发布于Cylon的收藏册,转载请著名原文链接~
记录一下,接了一个python2 django1.x的项目,很老了导致很多扩展无法安装
os version:macos catalina python version: 2.7.18
而django后端使用sqllite以外需要对应客户端引擎,而安装时编译依赖C客户端即实际mysql组件。
使用的数据库后端。 内建的数据库后端有:
‘django.db.backends.postgresql’ ‘django.db.backends.mysql’ ‘django.db.backends.sqlite3’ ‘django.db.backends.oracle’
并且修改配置实例
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'USER': 'mydatabaseuser',
'NAME': 'mydatabase',
'TEST': {
'NAME': 'mytestdatabase',
},
},
}
brew unlink mysql
error: command ‘gcc’ failed with exit status 1
creating build/temp.macosx-10.9-x86_64-2.7
gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql@5.7/5.7.32/include/mysql -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.9-x86_64-2.7/_mysql.o
gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-2.7/_mysql.o -L/usr/local/Cellar/mysql@5.7/5.7.32/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-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 'gcc' failed with exit status 1
解决方法:
# Required for mysqlclient, see brew info openssl
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
pip install MySQL-python
Reference:not-found-for-lssl
windows安装
pip install mysqlclient-1.3.12-cp36-cp36m-win_amd64.whl
Reference https://www.lfd.uci.edu/~gohlke/pythonlibs/
ubuntu安装
apt-get install libmysqld-dev
pip install MySQL-python
my_config.h file not found
creating build/temp.macosx-10.9-x86_64-2.7
gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/8.0.23_1/include/mysql -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.9-x86_64-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 'gcc' failed with exit status 1
解决:网上找了很多版本均无法解决,最后发现实际上与linux处理思路是一样的。
brew install mysql # 可以加版本 如 brew install mysq@5.7
brew unlink mysql
brew install mysql-connector-c # 这个是客户端
ln -snvf /usr/local/Cellar/mysql\@5.7/5.7.32/bin/mysql_config /usr/local/bin/ # 做个软连接,位置可能不一致
sed -i -e 's/libs="$libs -l "/libs="$libs -lmysqlclient -lssl -lcrypto"/g' /usr/local/bin/mysql_config
pip install MySQL-python
sh: mysql_config: command not found
sh: mysql_config: command not found
这个与上面类似,可以看到也是在PATH中找mysql_config
本文发布于Cylon的收藏册,转载请著名原文链接~
链接:https://www.oomkill.com/2021/04/mac-mysqlapi/
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」 许可协议进行许可。