安装setuptools时出错(无法解决的类型:str()< NoneType())

时间:2015-01-12 03:19:36

标签: python setuptools

Python 3.4.2,32位 - Win 8.1,64位

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

  1. pip install setuptools:

    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. 在具有管理员权限的PowerShell中运行(Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python -

    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
    
  3. (我现在不想安装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-3.4.2.msi并选择修复选项来修复python安装。但仍然没有setuptools:

      >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
      
    3. 我认为卸载并重新安装python会解决这个问题,但在尝试之前我想也许你可以帮我找到问题的原因和解决问题的正确方法。感谢。

3 个答案:

答案 0 :(得分:0)

而不是下载ez_setup.py,而是使用get-pip.py。从docs开始,如果未安装setuptools,则会先安装它。


由于您仍然收到错误,请尝试从Christoph Gohlke的Python扩展程序包for Windows存储库安装pipsetuptools。确保下载Python 3.4的32位安装程序。下载完成后,运行.exe个文件,希望一切都恢复正常。那里有大量的科学计算软件包,所以如果你想要numpy与英特尔的MKL相关联,而scipy使用增强版的numpy,那么就去吧!

答案 1 :(得分:0)

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

答案 2 :(得分:0)

我能够解决我的问题(在Win 8.1 64bit,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