Command "python setup.py egg_info" failed with error code

解决pip install MySQL-python 报Command "python setup.py egg_info" failed with error code 问题解决方法

此方法 可能对你不可行,我也是尝试了网上N种方法才解决好的,至于是哪种方法解决的我也不清楚

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/0w/d8plqgs953q5ftqc98xbbptw0000gn/T/pip-build-Uuy2jA/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/0w/d8plqgs953q5ftqc98xbbptw0000gn/T/pip-build-Uuy2jA/mysql-python/

1、执行xcode-select --install
会弹出一个窗口,点击安装等待安装完成

(py2env) DsHdeMacBook-Pro:bin dsh$ xcode-select --install
xcode-select: note: install requested for command line developer tools

2、执行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/0w/d8plqgs953q5ftqc98xbbptw0000gn/T/pip-build-Kssgvj/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/0w/d8plqgs953q5ftqc98xbbptw0000gn/T/pip-build-Kssgvj/MySQL-python/

3、使用brew 安装mysql

https://brew.sh/index_zh-cn.html

image.png

4、执行brew install mysql

Error: Cannot install mysql because conflicting formulae are installed.
  mysql-connector-c: because both install MySQL client libraries

Please `brew unlink mysql-connector-c` before continuing.

Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.

按照要求执行brew unlink mysql-connector-c
5、再次执行brew install mysql

==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.19.sierra.bottle.
Already downloaded: /Users/dsh/Library/Caches/Homebrew/mysql-5.7.19.sierra.bottle.tar.gz
==> Pouring mysql-5.7.19.sierra.bottle.tar.gz
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql/5.7.19: 322 files, 233MB

6、重新执行 pip install MySQL-python

Collecting MySQL-python
  Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: MySQL-python
  Running setup.py bdist_wheel for MySQL-python ... done
  Stored in directory: /Users/dsh/Library/Caches/pip/wheels/38/a3/89/ec87e092cfb38450fc91a62562055231deb0049a029054dc62
Successfully built MySQL-python
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.5

7、终于执行成功,😄

我使用的是mac 系统, ubuntu系统应该更这个步骤差不多,如果有问题可以留言讨论。或者你有更好的方法,或者更好的解释这个问题的方式,可以告诉我,谢谢。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在linux系统安装MySQL-Python模块一直在报这个错,Google搜索了很久,看了一些不靠谱的解决方案浪...
    Neulana阅读 12,503评论 2 1
  • 译者按:原文写于2011年末,虽然文中关于Python 3的一些说法可以说已经不成立了,但是作为一篇面向从其他语言...
    EarlGrey阅读 69,761评论 7 124
  • 这一点特别有必要反映在纪录片里,就是一个违反常识的真实情况。最精锐的部队在真实战场中也只有25%的人会持续向敌人开...
    Atlas岛阅读 3,229评论 1 2
  • 一别十载故人饮,清浊陈泪湿衣襟。 好酒壶中乾坤大,推杯问盏解初心。
    abe4c0570901阅读 864评论 0 2
  • 死亡是终点还是开始?无从知晓。本能地惧怕死亡,但终有一天我将独自死去。那个行走在苍茫大地间我的躯体,那一刻将会躺在...
    披着羽毛的猪阅读 1,833评论 5 3