[英]Can't install mysql-python with pip on MacOS 10.12.4
運行pip install mysql-python
時收到以下錯誤
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/b_/xh05hxwd0lzc3rm858jsypdc0000gn/T/pip-build-AWDYaP/mysql-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 53, in get_config
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
File "setup_posix.py", line 8, 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/b_/xh05hxwd0lzc3rm858jsypdc0000gn/T/pip-build-AWDYaP/mysql-python/
我跟着說明這周圍重新安裝setuptools的職位,我已經從重新安裝Python的https://www.python.org/
which -a python
給
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python
自安裝MacOS 10.12.4更新以來,似乎已發生該錯誤。
解決了這個
brew install mysql
pip install MySQL-python
如果仍然失敗,例如“ mysql-python的構建輪子失敗”,請嘗試
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python
這對我來說就像一種魅力。
這對我有用(macOS Mojave 10.14.2):
brew install mysql@5.7
brew link --force mysql@5.7
brew install mysql-client
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python
如果您像我一樣,並且在Mac上從源代碼安裝了mysql,則忘記建議使用brew的人-您的計算機已經具有mysql-connector-c。 如果您確實執行brew install mysql-connector-c,請執行brew brew卸載mysql-connector-c並嘗試再次pip install mysql-python(Python 3)。
這為我工作:
brew install mysql@5.7
brew link --force mysql@5.7
為了解決這個問題,我們應該編輯mysql_config文件。
為此,發出命令:
vi `which mysql_config`
這將在vi編輯器中打開mysql_config
。
按i
進入插入模式
現在找到線
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
對我來說,它位於第118行。以上行應更改為
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
現在按esc
按鈕退出插入模式,並通過在vi編輯器中發出命令:wq
保存添加的內容。
現在嘗試使用pip重新安裝MySQL-Python
模塊。
請注意,假定已安裝mysql
和openssl
對我來說,這工作:
brew install mysql-connector-c
pip install MySQL-python
pip install mysql-connector
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.