我发现,最近当我尝试使用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'
我知道这是一个老问题,但以下是我用来在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(参考这个答案)。这就是我解决问题的方法。