解决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.png4、执行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系统应该更这个步骤差不多,如果有问题可以留言讨论。或者你有更好的方法,或者更好的解释这个问题的方式,可以告诉我,谢谢。
网友评论