我发现,最近当我尝试使用pip安装Python包时,经常会得到以下错误。

我在网上找到了一个参考,一个人必须从下载目录中使用“python2 setup.py install”,并且确实发现如果我手动找到并下载包(从pypi),这将会工作。

但是,我不知道pip将包下载到哪里,和/或为什么它会以这种方式失败。

我尝试进行pip升级,但它也以类似的方式失败,出现了一堆“未知分发选项”错误(entry_points, zip_safe, test_suite, tests_require)!

皮普1.0.1 ActivePython 2.7

尝试使用ActiveState的pypm会失败,因为它们的库基数较小,而且不包括这些包。

C:\test>pip install requests-oauth
Downloading/unpacking requests-oauth
  Downloading requests-oauth-0.4.1.tar.gz
  Running setup.py egg_info for package requests-oauth
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
      warnings.warn(msg)
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
      warnings.warn(msg)
    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:
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
  warnings.warn(msg)

E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
  warnings.warn(msg)

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'

当前回答

安装分发,它随egg_info一起提供。

应该像pip安装分发一样简单。

从0.7版开始,Distribute已经被合并到Setuptools中。如果您使用的版本<=0.6,请使用pip install——upgrade setuptools或easy_install -U setuptools进行升级。

其他回答

由于分发已经合并回setuptools,现在建议安装/升级setuptools:

[sudo] pip install --upgrade setuptools

我知道这是一个老问题,但以下是我用来在Windows 7 / Python2上实际安装cassandra-driver的步骤。我有windows10 / Python3在家里,我今晚将测试这个。我已经确认这也适用于Windows 10的Python 2和3。

问题

Command "python setup.py egg_info" failed with error code 1 in c:\users\Frito\appdata\local\temp\pip-build-7dgmdc\cassandra-driver

TL;博士的解决方案

已安装https://www.microsoft.com/en-us/download/details.aspx?id=44266 (Microsoft Visual c++ Compiler for Python 2.7)

解决方案(我希望有人能解释为什么这样做)

尝试pip安装cassandra-driver,并得到上述错误消息 尝试pip install——pre cassandra-driver,得到以下错误

distutils.errors.DistutilsError: Setup script exited with error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it from http://aka.ms/vcpython27 Command "c:\users\Frito\.virtualenvs\symdash\scripts\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\Frito\\appdata\\local\\temp\\pip-build-sesxxu\\cassandra-driver\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\Frito\appdata\local\temp\pip-ujsxsk-record\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\Frito\.virtualenvs\symdash\include\site\python2.7\cassandra-driver" failed with error code 1 in c:\users\Frito\appdata\local\temp\pip-build-sesxxu\cassandra-driver

安装Microsoft Visual c++编译器for Python 2.7 成功执行pip install——pre cassandra-driver 成功执行pip uninstall cassandra-driver 成功执行pip install cassandra-driver

重申一下,我真的不确定为什么这样做有效。现在我的两个主要结论是,要么是c++编译器是必需的,要么是第一次运行——pre选项安装了一些'常规'安装中缺少的依赖项。我今晚下班后会更新更多细节。

我还遇到了类似的错误消息 "命令'python setup.py egg_info'失败,错误码为1" 当我想用pip命令安装cairosvg时,请在虚拟环境中安装cairosvg。

然后在运行pip3 install cairosvg之前,我已经尝试了pip install -upgrade pip和pip install -upgrade setuptools,但我仍然得到这个错误。

我可以在安装命令前使用sudo来消除这个错误:sudo pip install cairosvg。 但是请注意,带有sudo的命令将为系统python安装包,而不是为虚拟环境安装包。

因此,我进一步检查错误消息,发现我在安装cairocffi时得到了错误。然后,在安装cairosvg之前,我安装了特定版本的cairocffi(参考这个答案)。这就是我解决问题的方法。

在CentOS 6.5上,干净安装的简短回答是:

Yum -y安装python-pip pip install -U pip pip install -U setuptools pip install -U setuptools

你没有看到两次,你必须运行setuptools升级两次。答案如下:

使用yum安装python-pip包会带来python-setuptools作为依赖项。这是一个相当旧的版本,因此它实际上安装的是发行版(0.6.10)。安装包管理器后,我们通常想要更新它,所以我们执行pip install -U pip。对我来说,pip的当前版本是1.5.6。

现在我们去更新setuptools,这个版本的pip足够聪明,它知道它应该首先删除旧版本的distribute。它会这样做,但随后不会安装最新版本的setuptools,而是安装setuptools (0.6c11)。

在这一点上,由于这个非常旧的setuptools版本,所有的东西都被破坏了,但我们实际上已经成功了一半。如果我们现在再次运行完全相同的命令,pip install -U setuptools,旧版本的setuptools将被删除,并安装5.5.1版本。我不知道为什么pip没有把我们直接带到新版本,但这就是正在发生的事情,希望它能帮助其他人看到这一点,并知道你没有疯掉。

我遇到了这个问题,以及在OS X v10.9 (Mavericks)上使用Brewed Python时的其他一些问题。

sudo pip install --upgrade setuptools

不适合我,我认为我的setuptools/分发设置是拙劣的。

我终于通过跑步让它起作用了

sudo easy_install -U setuptools