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

早过忘川 提交于 2020-01-06 12:47:52

问题


Python 3.4.2, 32 bit - Win 8.1, 64 bit

First I was trying to upgrade setuptools, but it was not successful. So I decided to uninstall the previous version. Now I can't install setuptools. I have tried the following:

  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. Running (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python - in a powershell with admin privileges:

    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
    

(I'm not willing to install Internet Explorer right now, but if you think I have to, then I will.)

  1. Downloaded the ez_setup.py and ran it:

    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. Repairing python installation by running python-3.4.2.msi and choosing the repair option. But still no 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
    

I think uninstalling and reinstalling python would fix the problem, but before trying that I thought maybe you can help me to find the cause of the problem and the right way to fix this. Thanks.


回答1:


I was able to solve my problem (on Win 8.1 64bit, Python 3.4.2) with the change suggested here:

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




回答2:


Instead of downloading ez_setup.py, use get-pip.py instead. From the docs, if setuptools is not installed, it will install it first.


Since you're still getting an error, try installing 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, which uses the enhanced version of numpy, go right ahead!




回答3:


Well it seemed to me that my python installation was completely messed up. It could have been related to a temporary installation of python 2 on my system a few weeks ago. Anyway, I thought it would be easier for me to just uninstall and reinstall the whole thing. So I uninstalled python and then reinstalled, but even that was not enough. Finally, I manually deleted C:\Python34 and reinstalled python and now it works fine.



来源:https://stackoverflow.com/questions/27894825/error-in-installing-setuptools-unorderable-types-str-nonetype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!