无法在 MacOS 10.12.4 上使用 pip 安装 mysql-python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43634584/
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
Can't install mysql-python with pip on MacOS 10.12.4
提问by Franco
Following error recieved when running pip install mysql-python
运行时收到以下错误 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/
I followed the instructions in thispost around reinstalling setuptools and I have reinstalled Python from https://www.python.org/
我按照这篇文章中关于重新安装 setuptools的说明进行操作,并且我已经从https://www.python.org/重新安装了 Python
which -a python
gives
which -a python
给
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python
The error seems to have occurred since installing MacOS 10.12.4 update
该错误似乎是在安装 MacOS 10.12.4 更新后发生的
回答by Franco
Solved with this
解决了这个
brew install mysql
pip install MySQL-python
回答by Golden Thumb
If you still failed with something like "Failed building wheel for mysql-python", try
如果您仍然因“mysql-python 的构建轮失败”之类的问题而失败,请尝试
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python
which works like a charm for me.
这对我来说就像一种魅力。
回答by Ivan Kvas
This worked for me (macOS Mojave 10.14.2):
这对我有用(macOS Mojave 10.14.2):
brew install [email protected]
brew link --force [email protected]
brew install mysql-client
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python
回答by mpoletto
If you are like me and installed mysql from source in mac, then forget who are suggest to use brew - your machine already has mysql-connector-c. If you did brew install mysql-connector-c, do brew uninstall mysql-connector-c and try pip install mysql-python again (Python 3).
如果你像我一样在 mac 中从源代码安装了 mysql,那么忘记谁建议使用 brew - 你的机器已经有 mysql-connector-c。如果您执行 brew install mysql-connector-c,请执行 brew uninstall mysql-connector-c 并再次尝试 pip install mysql-python (Python 3)。
回答by Andrews Agyemang Opoku
回答by padippist
To fix this we should edit mysql_config file.
要解决这个问题,我们应该编辑 mysql_config 文件。
For this, issue the command:
为此,发出命令:
vi `which mysql_config`
This will open up the mysql_config
in vi editor.
这将打开mysql_config
in vi 编辑器。
Press i
to be in insert mode
按下i
进入插入模式
Now find lines
现在找到线
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
for me it is on line 118. The above lines should be changed to
对我来说,它在第 118 行。上面的几行应该改为
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
Now press esc
button to exit from the insert mode and save the added content
by issuing command:wq
in vi editor.
现在按下esc
按钮退出插入模式并通过:wq
在 vi 编辑器中发出命令来保存添加的内容。
Now try to reinstalling the MySQL-Python
module using pip.
现在尝试MySQL-Python
使用 pip重新安装模块。
Note it is assumed that mysql
and openssl
are installed
请注意,假设mysql
和openssl
已安装
回答by David Webster
For me this worked:
对我来说这有效:
brew install mysql-connector-c
pip install MySQL-python
pip install mysql-connector