安装 setuptools 时出错(不可排序的类型:str() < NoneType())

Error in installing setuptools (unorderable types: str() < NoneType())

Python 3.4.2,32 位 - Win 8.1,64 位

首先我尝试升级 setuptools,但没有成功。所以我决定卸载以前的版本。现在我无法安装 setuptools。我尝试了以下方法:

  1. pip 安装设置工具:

    Exception:
    Traceback (most recent call last):
      File "C:\Python34\lib\site-packages\pip\basecommand.py", line 232, in main
        status = self.run(options, args)
      File "C:\Python34\lib\site-packages\pip\commands\install.py", line 339, in run
    
        requirement_set.prepare_files(finder)
      File "C:\Python34\lib\site-packages\pip\req\req_set.py", line 229, in prepare_
    files
        req_to_install.check_if_exists()
      File "C:\Python34\lib\site-packages\pip\req\req_install.py", line 928, in chec
    k_if_exists
        self.satisfied_by = pkg_resources.get_distribution(self.req)
      File "C:\Python34\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", li
    ne 461, in get_distribution
        dist = get_provider(dist)
      File "C:\Python34\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", li
    ne 341, in get_provider
        return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
      File "C:\Python34\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", li
    ne 870, in require
        needed = self.resolve(parse_requirements(requirements))
      File "C:\Python34\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", li
    ne 740, in resolve
        env = Environment(self.entries)
      File "C:\Python34\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", li
    ne 927, in __init__
        self.scan(search_path)
      File "C:\Python34\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", li
    ne 957, in scan
        self.add(dist)
      File "C:\Python34\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", li
    ne 977, in add
        dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
    TypeError: unorderable types: str() < NoneType()
    
  2. 运行 (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python - 在具有管理员权限的 powershell 中:

    PS C:\Windows\system32> > (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python -
    Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or
    Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
    At line:1 char:4
    + > (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python -
    +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
        + FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    

(我现在不想安装 Internet Explorer,但如果您认为我必须安装,那么我会安装。)

  1. 下载了 ez_setup.py 和 运行 它:

    Installing Setuptools
    running install
    Traceback (most recent call last):
      File "setup.py", line 180, in <module>
        dist = setuptools.setup(**setup_params)
      File "C:\Python34\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "C:\Users\a\AppData\Local\Temp\tmpo7o_bqrd\setuptools-11.3.1\setuptools\c
    ommand\install.py", line 67, in run
        self.do_egg_install()
      File "C:\Users\a\AppData\Local\Temp\tmpo7o_bqrd\setuptools-11.3.1\setuptools\c
    ommand\install.py", line 103, in do_egg_install
        cmd.ensure_finalized()  # finalize before bdist_egg munges install cmd
      File "C:\Python34\lib\distutils\cmd.py", line 107, in ensure_finalized
        self.finalize_options()
      File "C:\Users\a\AppData\Local\Temp\tmpo7o_bqrd\setuptools-11.3.1\setuptools\c
    ommand\easy_install.py", line 319, in finalize_options
        self.index_url, search_path=self.shadow_path, hosts=hosts,
      File "C:\Users\a\AppData\Local\Temp\tmpo7o_bqrd\setuptools-11.3.1\setuptools\p
    ackage_index.py", line 269, in __init__
        Environment.__init__(self,*args,**kw)
      File "C:\Users\a\AppData\Local\Temp\tmpo7o_bqrd\setuptools-11.3.1\pkg_resource
    s\__init__.py", line 975, in __init__
        self.scan(search_path)
      File "C:\Users\a\AppData\Local\Temp\tmpo7o_bqrd\setuptools-11.3.1\pkg_resource
    s\__init__.py", line 1005, in scan
        self.add(dist)
      File "C:\Users\a\AppData\Local\Temp\tmpo7o_bqrd\setuptools-11.3.1\pkg_resource
    s\__init__.py", line 1025, in add
        dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
    TypeError: unorderable types: str() < NoneType()
    Something went wrong during the installation.
    See the error message above.
    
  2. 正在修复 python 通过 运行 python-3.4.2.msi 安装并选择修复选项。但是仍然没有安装工具:

    >pip install scipy -U
    Collecting scipy from https://pypi.python.org/packages/source/s/scipy/
    .0.tar.gz#md5=639112f077f0aeb6d80718dc5019dc7a
      Using cached scipy-0.15.0.tar.gz
      setuptools must be installed to install from a source distribution
    

我认为卸载并重新安装 python 可以解决问题,但在尝试之前我想也许您可以帮助我找出问题的原因以及解决问题的正确方法。谢谢。

不要下载ez_setup.py,而是使用get-pip.py instead. From the docs,如果setuptools没有安装,它会先安装。


由于您仍然遇到错误,请尝试安装 pip and setuptools from Christoph Gohlke's Python Extension Packages for Windows repository. Make sure you download the 32-bit installers for Python 3.4. Once downloaded, run the .exe files and hopefully everything will be back to normal. There are tons of scientific computing packages there, so if you want numpy linked against Intel's MKL, and scipy,它使用增强版的 numpy,继续吧!

嗯,在我看来,我的 python 安装完全一团糟。它可能与几周前在我的系统上临时安装 python 2 有关。无论如何,我认为卸载并重新安装整个东西对我来说会更容易。所以我卸载了 python 然后重新安装,但即使这样还不够。最后,我手动删除了C:\Python34并重新安装了python,现在可以正常使用了。

我能够通过此处建议的更改解决我的问题(在 Win 8.1 64 位,Python 3.4.2 上):

https://bitbucket.org/pypa/setuptools/pull-request/122/ensure-py_version-and-platform-are-str-in/diff#chg-pkg_resources/init.py