无法在MacOS 10.12.4上使用pip安装mysql-python

时间:2017-04-26 12:43:28

标签: python macos pip

运行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/

我按照this帖子中的说明重新安装setuptools,我从https://www.python.org/重新安装了Python

which -a python给出了

/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python

自安装MacOS 10.12.4更新

以来,似乎发生了错误

7 个答案:

答案 0 :(得分:28)

解决了这个

brew install mysql
pip install MySQL-python

答案 1 :(得分:11)

如果您仍然遇到类似“为mysql-python构建轮子失败”的问题,请尝试

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python

对我来说就像是一种魅力。

答案 2 :(得分:5)

这对我有用(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

答案 3 :(得分:4)

如果你像我一样从mac中安装mysql,那么忘记谁建议使用brew - 你的机器已经有了mysql-connector-c。如果你做了brew install mysql-connector-c,请执行brew uninstall mysql-connector-c并再次尝试pip install mysql-python(Python 3)。

答案 4 :(得分:2)

这对我有用:

    brew install mysql@5.7
    brew link --force mysql@5.7

答案 5 :(得分:0)

要解决此问题,我们应编辑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模块。

请注意,假设已安装mysqlopenssl

答案 6 :(得分:0)

这对我来说很有效:

brew install mysql-connector-c 
pip install MySQL-python
pip install mysql-connector