![](/img/trans.png)
[英]Attempted install of Python 3 via homebrew fails on Mac OS X Sierra
[英]Install mysqlclient for Django Python on Mac OS X Sierra
我已經安裝了
我想將 MySQL 與 Django 一起使用,但在安裝 mysql 連接器后,我嘗試在$ 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/
我需要以下內容來構建/安裝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/"
然后我可以pip wheel mysqlclient
/ pip install mysqlclient
成功
我也遇到過這個問題,下面是我的步驟:
1. brew install mysql-connector-c
2.pip pip install mysqlclient
然后遇到這個錯誤,我已經跟蹤了源代碼,但是解決了這個然后又出現了另一個錯誤。
所以我改變了安裝mysqlclient的方式,只是:
brew install mysql
pip install mysqlclient
這對我有用,沒有發生任何錯誤。
如果您不打算在計算機中安裝mysql
,請安裝mysql-client
而不是mysql
brew install mysql-client
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
pip install mysqlclient
導出 LDFLAGS="-L/usr/local/opt/openssl/lib"
導出 CPPFLAGS="-I/usr/local/opt/openssl/include"
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 perfectly
對於 Mac:首先從 App Store 下載 Xcode,從https://dev.mysql.com/downloads/workbench/下載 MySqlWorkbench
在終端中運行以下命令,
$ brew install mysql
$ export PATH=$PATH:/Applications/MySQLWorkbench.app/Contents/MacOS
$ xcode-select --install
$ pip install mysqlclient
使用 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
今天這對我有用,在使用brew install mysql
使用 Homebrew 安裝 MySQL 服務器之后:
MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags` \
MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs` \
pip install mysqlclient
對於我的 mac 操作系統,我不需要指定路徑,因為 brew 會為您執行此操作。 我只是做了以下命令,
brew install mysql
brew install mysql-client
pip3 install mysqlclient
一切都很完美。
MAC M1運行
xcode-select --install
然后運行
pip install mysqlclient
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.