【问题标题】:Can't install mysql-python with pip on MacOS 10.12.4无法在 MacOS 10.12.4 上使用 pip 安装 mysql-python
【发布时间】:2017-09-23 21:06:26
【问题描述】:

运行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 更新后出现的

【问题讨论】:

    标签: python macos pip


    【解决方案1】:

    解决了这个

    brew install mysql
    pip install MySQL-python
    

    【讨论】:

    • 感谢您的解决方案。这让我发疯了。实际上我必须同时做你和其他人: brew unlink mysql-connector-c 然后 brew install mysql
    • 在此之后添加brew link mysql ^
    • 我确定mysql已安装并链接,然后运行 ​​pip install MySQL-python 还是同样的错误
    【解决方案2】:

    如果您仍然因“mysql-python 构建失败”之类的内容失败,请尝试

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

    这对我来说就像一个魅力。

    【讨论】:

    • 谢谢!为我节省了很多时间!
    • 太棒了!非常感谢!也节省了我的时间:)
    • 这是唯一对我有用的解决方案,非常感谢!!
    • 也拯救了我的一天。
    • 也保存了我的期末成绩项目。
    【解决方案3】:

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

    【讨论】:

    • 谢谢!这对我有用。还要处理莫哈韦沙漠。
    • 谢谢,为我节省了很多时间。在 macOS Mojave 上工作。
    【解决方案4】:

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

    【讨论】:

      【解决方案5】:

      这对我有用:

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

      【讨论】:

        【解决方案6】:

        要解决这个问题,我们应该编辑 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 编辑器中发出 command:wq

        现在尝试使用 pip 重新安装 MySQL-Python 模块。

        请注意,假设已安装 mysqlopenssl

        【讨论】:

        • 这个解决方案是唯一对我有用的解决方案。谢谢!
        【解决方案7】:

        对我来说这很有效:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-10-03
          • 2018-10-12
          • 2013-09-05
          • 2016-04-02
          • 1970-01-01
          • 2018-11-29
          • 2016-01-24
          相关资源
          最近更新 更多