解决mac os上pip安装mysqlclient失败的问题:library not found for -lgsl(lssl)
程序员文章站
2022-05-29 11:34:59
...
解决mac os上pip安装mysqlclient失败的问题
系统概述:
- mac os mojave 10.14.5
- python 2.7 virtualenvwrapper
- pip 2 virtualenvwrapper
第一次尝试:
here
PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
^
1 warning generated.
gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-2.7/MySQLdb/_mysql.o -L/usr/local/Cellar/[email protected]/5.7.25/lib -lmysqlclient -lgsl -lcrypto -o build/lib.macosx-10.9-x86_64-2.7/MySQLdb/_mysql.so
ld: library not found for -lgsl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1
在google上做了多次搜索结果的尝试后无法解决。便区查看了mysqlclient的文档 https://pypi.org/project/mysqlclient/ 在文档中有提示:
Change
# on macOS, on or about line 112:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
to
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
再次尝试pip install mysqlclient还是报错只不过这次报错不一样了,如下:
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/intobject.h:34:46: note: passing argument to parameter here
PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
^
1 warning generated.
gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-2.7/MySQLdb/_mysql.o -L/usr/local/Cellar/[email protected]/5.7.25/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-2.7/MySQLdb/_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
----------------------------------------
再次搜索关键词
pip install mysqlclient mac
找到了这篇博文,pipenv install mysqlclient on MacOSX - Shan Dou - Medium参考博主的操作获得了正确的方法:
正确的方法
在这之前请确保你安装了mysql-connector-c,mysql-connector-c的安装可参考:mysqlclient · PyPI
brew info openssl
获取如下的结果:
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
For pkg-config to find openssl you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
然后执行如下操作:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
# 当前虚拟环境的命令行中执行
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
上一篇: pip安装出错
下一篇: 安装mysqlclient出错