Note for situation and solution and more

TL;DR: Just pip install -U setuptools before the package which depends on setuptools upgrade it.


A build on Travis CI of one of my side projects got error AttributeError: 'Distribution' object has no attribute 'install_requires' while upgrading setuptools from 36.2.0 to 36.7.0 with Python 3.6.2 build job. This build also has Python 3.4 and Python 3.5 build jobs which have no erorr because they didn't need to upgrade setuptools.

What's the problem

Travis CI image with os: linux and python: 3.6 labels default installed Python 3.6.2, pip 9.0.1 and setuptools 36.2.0 in this time. The problem occured while pip install -U pytest was running because the default --upgrade-strategy of -U / --upgrade option of pip is "eager" which will upgrade all dependent packages to newest version.

See part of pip install -h for detail:
-U, --upgrade Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used. --upgrade-strategy <upgrade_strategy> Determines how dependency upgrading should be handled. "eager" - dependencies are upgraded regardless of whether the currently installed version satisfies the requirements of the upgraded package(s). "only-if-needed" - are upgraded only when they do not satisfy the requirements of the upgraded package(s).

This made pip install -U pytest upgrade setuptools from 36.2.0 to 36.7.0 while installing pytest-3.2.1 and got the error below:

Found existing installation: setuptools 36.2.0  
    Uninstalling setuptools-36.2.0:  
      Successfully uninstalled setuptools-36.2.0  
  Rolling back uninstall of setuptools  
Traceback (most recent call last):  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/pip/", line 215, in main  
    status =, args)  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/pip/commands/", line 342, in run  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/pip/req/", line 784, in install  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/pip/req/", line 851, in install  
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/pip/req/", line 1064, in move_wheel_files  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/pip/", line 247, in move_wheel_files  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/pip/", line 140, in distutils_scheme  
    d = Distribution(dist_args)  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/setuptools/", line 365, in __init__  
  File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/setuptools/", line 372, in _finalize_requires  
    if not self.install_requires:  
AttributeError: 'Distribution' object has no attribute 'install_requires'  

How to fix it

Although there are many comments on pypa/setuptools #1086 and pypa/setuptools #1101, I didn't know the exact reason after I read them. But after a little digging on the GitHub, I finally got some clues.

This problem had already been fixed in pypa/setuptools #1089, but why I still got this problem? Because this fix is in setuptools-36.2.1 not in setuptools-36.2.0, if you use setuptools-36.2.0 you will still encounter this problem.

Here's a workarond for this problem which is same as the TL;DR, just pip install --upgrade setuptools to upgrade it.

Further Discussion

But why? why pip install --upgrade setuptools works? why pip install -U pytest doesn't? Aren't these two methods just remove setuptools-36.2.0 and install a newer setuptools? According to the result, it's not.

I guess I might have to spend some time on figuring the workflow of pip?




如果覺得這篇文章對你有幫助, 除了留言讓我知道外, 或許也可以考慮請我喝杯咖啡, 不論金額多寡我都會非常感激且能鼓勵我繼續寫出對你有幫助的文章。

If this blog post happens to be helpful to you, besides of leaving a reply, you may consider buy me a cup of coffee to support me. It would help me write more articles helpful to you in the future and I would really appreciate it.

Related Posts