在 Mac OS X Sierra 上为 Django Python 安装 mysqlclient
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43612243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install mysqlclient for Django Python on Mac OS X Sierra
提问by Андрей Морченко
I have already installed
我已经安装了
- Python 2.7.13
- Django 1.11
- MySQL 5.7.17
- 蟒蛇 2.7.13
- Django 1.11
- MySQL 5.7.17
I want use MySQL with Django, but after install mysql connector I was try to install mysqlclient for Python on $ pip install mysqlclient
, but I have this issue:
我想将 MySQL 与 Django 一起使用,但是在安装 mysql 连接器后,我尝试在 上为 Python 安装 mysqlclient $ pip install mysqlclient
,但是我遇到了这个问题:
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/y_/c31n_1v12v169zfv829p_v_80000gn/T/pip-build-f51KhW/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 54, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "setup_posix.py", line 12, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/y_/c31n_1v12v169zfv829p_v_80000gn/T/pip-build-f51KhW/mysqlclient/
回答by Anthony Sottile
I needed the following to build / install mysqlclient
我需要以下内容来构建/安装 mysqlclient
brew install mysql-client
# mysql-client is not on the `PATH` by default
export PATH="/usr/local/opt/mysql-client/bin:$PATH"
# openssl is not on the link path by default
export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/"
Then I could pip wheel mysqlclient
/ pip install mysqlclient
successfully
然后我可以pip wheel mysqlclient
/pip install mysqlclient
成功
回答by Neal Lee
I have encountered this problem too,below is my step:
我也遇到过这个问题,下面是我的步骤:
1.brew install mysql-connector-c
1.brew install mysql-connector-c
2.pip install mysqlclient
2.pip install mysqlclient
and then encountered this error,i have Traced the source code,but solved this one then the other error occured.
然后遇到这个错误,我已经跟踪了源代码,但是解决了这个错误然后发生了另一个错误。
so i changed the way to install mysqlclient,just :
所以我改变了安装mysqlclient的方式,只是:
1.brew install mysql
1.brew install mysql
2.pip install mysqlclient
2.pip install mysqlclient
this worked for me,no any errors occured.
这对我有用,没有发生任何错误。
回答by edilio
Install mysql-client
instead of mysql
if you don't plan to have mysql
in your computer
安装mysql-client
而不是mysql
如果您不打算mysql
在您的计算机中安装
brew install mysql-client
brew install mysql-client
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
source ~/.bash_profile
pip install mysqlclient
pip install mysqlclient
export LDFLAGS="-L/usr/local/opt/openssl/lib"
导出 LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
导出 CPPFLAGS="-I/usr/local/opt/openssl/include"
回答by elhay efrat
brew install/upgrade/reinstall mysql
brew install mysql-client
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
pip install mysqlclient works
works perfectly
回答by gautamyadav
For Mac: first download Xcode from App Store and MySqlWorkbench from https://dev.mysql.com/downloads/workbench/
对于 Mac:首先从 App Store 下载 Xcode,从https://dev.mysql.com/downloads/workbench/下载 MySqlWorkbench
Run the following commands in terminal,
在终端中运行以下命令,
$ brew install mysql
$ export PATH=$PATH:/Applications/MySQLWorkbench.app/Contents/MacOS
$ xcode-select --install
$ pip install mysqlclient
回答by Julian Maya
Install mysql using brew and add it to the path:
使用 brew 安装 mysql 并将其添加到路径中:
$ brew install mysql
$ export PATH=/usr/local/mysql/bin:$PATH
$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
$ pip install mysqlclient