pip安装失败,错误:无效命令'egg_info'。

10

最近我从Python官网下载了Python,并且在Mac OSX自带的Python版本之外安装了它。然后,我开始在pip上安装软件包时遇到了问题。

sudo pip install -vvv pygoogle

将输出以下内容:

The directory '/Users/robot/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/robot/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pygoogle
  Getting page https://pypi.python.org/simple/pygoogle/
  Starting new HTTPS connection (1): pypi.python.org
  "GET /simple/pygoogle/ HTTP/1.1" 200 233
  1 location(s) to search for versions of pygoogle:
  * https://pypi.python.org/simple/pygoogle/
  Getting page https://pypi.python.org/simple/pygoogle/
  "GET /simple/pygoogle/ HTTP/1.1" 200 233
  Analyzing links from page https://pypi.python.org/simple/pygoogle/
    Found link https://pypi.python.org/packages/source/p/pygoogle/pygoogle-0.6.tar.gz#md5=f9053f1b7350b899811a7c9226c8a2cb (from https://pypi.python.org/simple/pygoogle/), version: 0.6
    Skipping link http://www.google.com/apis/ (from https://pypi.python.org/simple/pygoogle/); not a file
  "GET /packages/source/p/pygoogle/pygoogle-0.6.tar.gz HTTP/1.1" 200 33672
  Downloading pygoogle-0.6.tar.gz
  Downloading from URL https://pypi.python.org/packages/source/p/pygoogle/pygoogle-0.6.tar.gz#md5=f9053f1b7350b899811a7c9226c8a2cb (from https://pypi.python.org/simple/pygoogle/)
  Running setup.py (path:/private/tmp/pip-build-1jAoXq/pygoogle/setup.py) egg_info for package pygoogle
    Running command python setup.py egg_info
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'
    Complete output from command python setup.py egg_info:
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'

    ----------------------------------------
Cleaning up...
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-1jAoXq/pygoogle
Exception information:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/commands/install.py", line 282, in run
    requirement_set.prepare_files(finder)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 334, in prepare_files
    functools.partial(self._prepare_file, finder))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 321, in _walk_req_to_install
    more_reqs = handler(req_to_install)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 505, in _prepare_file
    abstract_dist.prep_for_dist()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 123, in prep_for_dist
    self.req_to_install.run_egg_info()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 407, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/utils/__init__.py", line 732, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-1jAoXq/pygoogle

我已经尝试了下列所有方法,但它们只是告诉我包setuptools已经安装好了。

sudo pip install setuptools
sudo pip install [--upgrade] setuptools
easy_install [-U] setuptools
请注意以下命令输出:
where python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python

which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

where pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
/usr/local/bin/pip

which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip

echo $SHELL
/bin/zsh

我的.zprofile文件内容:

# Setting PATH for Python 2.7
# The orginal version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
2个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
16

尝试执行pip install --upgrade setuptoolseasy_install -U setuptools

或者

下载此文件并运行python ez_setup.py


4
下载该文件并运行ez_setup.py即可解决。谢谢。 - thetao
@KOHTPOJIEP 有两个答案,你可以尝试第二个。下载该文件并执行 python ez_setup.py。 - Jameel Grand
@Jameel Grand 我已经尝试了这两个。第一个出现错误“无法执行文件...”。我尝试修复它,但我找到的解决方案也没有起作用。第二个根本没有任何效果。 - KOHTPOJIEP
运行 pip install --upgrade setuptools 然后运行 easy_install PackageName 解决了我的问题,其中 PackageName 是我最初尝试使用 pip 安装但失败的包的名称。 - Mohyaddin Alaoddin

0

我在Centos7上使用postgresql 9.6安装psycopg2时遇到了同样的错误。

我扩展了PATH变量,问题得到了解决:

PATH=$PATH:/usr/pgsql-9.1/bin/

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,