134

Does anybody encounter this warning when executing python setup.py install of a PyPI package?

install_requires defines what the package requires. A lot of PyPI packages have this option. How can it be an "unknown distribution option"?

5
  • 1
    Possible duplicate of Adding 'install_requires' to setup.py when making a python package
    – tripleee
    Oct 2, 2017 at 4:34
  • @tripleee maybe, but this question was asked earlier than that one.
    – Tyler Liu
    Oct 6, 2017 at 10:06
  • Question age is a secondary concern but I don't have a strong opinion either way. If you would like the duplicate nomination to go the other way around, maybe create a Meta Stack Overflow question for visibility. For me personally, the other question's accepted answer helped me more, because it is more direct and focused. You don't seem to ever have accepted any of these answers, so that's a factor you could actually change.
    – tripleee
    Oct 6, 2017 at 10:11
  • 1
    @tripleee if you read this thread carefully you will realize that there isn't a perfect answer at all. So I don't know which answer to accept. I don't want to mislead people by selecting an answer which cannot even convince myself.
    – Tyler Liu
    Oct 8, 2017 at 2:56
  • Please follow the official documentation and use import setuptools; setuptools.setup(). See: packaging.python.org/tutorials/packaging-projects/…
    – guettli
    Sep 10, 2020 at 20:19

10 Answers 10

102
+100

python setup.py uses distutils which doesn't support install_requires. setuptools does, also distribute (its successor), and pip (which uses either) do. But you actually have to use them. I.e. call setuptools through the easy_install command or pip install.

Another way is to import setup from setuptools in your setup.py, but this not standard and makes everybody wanting to use your package have to have setuptools installed.

5
  • 3
    Say I want to use pip, then how do I run the setup.py file if I only want to build an extension in-place?
    – Fred Foo
    May 24, 2012 at 11:41
  • 13
    The warning doesn't prevent you from packaging your code, so you can run python setup.py sdist and install it with pip install resulting_package.tar.gz. You can also use pip install -e to install directly from source, but I always preferred to install from package or from repository directly.. May 24, 2012 at 12:05
  • This is a little messed up. You can always try to import setup from setuptools first, otherwise go with distutils and get the warning. If it's in pypy, however, you might end up with "Too many open files" due to setuptools not closing descriptors properly (even on Debian, with the default ulimit -n of 1024): bugs.pypy.org/issue878
    – fiorix
    Jun 13, 2012 at 8:08
  • 1
    See my answer - as far as I can tell, this is just a straight up bug in setuptools. The user isn't doing anything wrong, setuptools is.
    – ncoghlan
    Jul 2, 2013 at 12:36
  • This indirectly answers my question: I got the error as a result of running pip install pendulum==1.4.4. Running pip install setuptools --upgrade cleared the error. May 2, 2019 at 20:25
69

This was the first result on my google search, but had no answer. I found that upgrading setuptools resolved the issue for me (and pip for good measure)

pip install --upgrade pip
pip install --upgrade setuptools

Hope this helps the next person to find this link!

2
  • This resolved it for me also. (Python 3.4, trying to pip3 install neovim-remote.) Dec 10, 2018 at 19:23
  • This worked for me. Was trying to install mako on Python 2.7.16. Got a similar Unknown Distribution option. Pip was OK but setuptools went to 41.0.1 from 40.6.2. Then Mako installed A-OK.
    – Max Yaffe
    Aug 11, 2019 at 20:20
20

I'm on a Mac with python 2.7.11. I have been toying with creating extremely simple and straightforward projects, where my only requirement is that I can run python setup.py install, and have setup.py use the setup command, ideally from distutils. There are literally no other imports or code aside from the kwargs to setup() other than what I note here.

I get the error when the imports for my setup.py file are:

from distutils.core import setup

When I use this, I get warnings such as

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'entry_points' warnings.warn(msg)

If I change the imports (and nothing else) to the following:

from distutils.core import setup
import setuptools  # noqa

The warnings go away.

Note that I am not using setuptools, just importing it changes the behavior such that it no longer emits the warnings. For me, this is the cause of a truly baffling difference where some projects I'm using give those warnings, and some others do not.

Clearly, some form of monkey-patching is going on, and it is affected by whether or not that import is done. This probably isn't the situation for everyone researching this problem, but for the narrow environment in which I'm working, this is the answer I was looking for.


This is consistent with the other (community) comment, which says that distutils should monkeypatch setuptools, and that they had the problem when installing Ansible. Ansible appears to have tried to allow installs without having setuptools in the past, and then went back on that.

https://github.com/ansible/ansible/blob/devel/setup.py

A lot of stuff is up in the air... but if you're looking for a simple answer for a simple project, you should probably just import setuptools.

1
  • 1
    Adding import setuptools also miraculously resolved the issue for me on ubuntu 16.04 with python 3.5.
    – kuropan
    Jan 24, 2019 at 11:47
17

ATTENTION! ATTENTION! Imperfect answer ahead. To get the "latest memo" on the state of packaging in the Python universe, read this fairly detailed essay.

I have just ran into this problem when trying to build/install ansible. The problem seems to be that distutils really doesn't support install_requires. Setuptools should monkey-patch distutils on-the-fly, but it doesn't, probably because the last release of setuptools is 0.6c11 from 2009, whereas distutils is a core Python project.

So even after manually installing the setuptools-0.6c11-py2.7.egg running setup.py only picks up distutils dist.py, and not the one from site-packages/setuptools/.

Also the setuptools documentation hints to using ez_setup and not distutils.

However, setuptools is itself provided by distribute nowadays, and that flavor of setup() supports install_requires.

4
  • 1
    Downvoted, as this answer contains some disinformation and confusion as to what different things are. ez_setup.py, for example, is a bootstrap installer for setuptools and is not something one would use "instead of" distutils. Most PyPI packages are not "simply wrong".
    – Iguananaut
    Jun 4, 2013 at 18:23
  • 1
    @Iguananaut, thanks for reviewing the answer; I've edited it.
    – PAStheLoD
    Jun 4, 2013 at 23:37
  • Oh cool, thanks. I'll re-upvote in that case :) Nick Coghlan's essay that you linked to is one I've shared around with my coworkers before to try to get them to wrap their heads around this stuff.
    – Iguananaut
    Jun 5, 2013 at 14:37
  • Great essay about the state of things in March 2013. One question... The author states: "The setuptools and distribute projects are in the process of merging back together, but the merger isn’t complete yet (I will update this essay as soon as that changes)." Does anyone know what the state of things is so far as of 2019? With Python 2.7's End of Life date quickly approaching, lots of python packages will be in the process of updating & re-packaging.
    – TrinitronX
    Oct 1, 2019 at 19:23
9

In conclusion:

distutils doesn't support install_requires or entry_points, setuptools does.

change from distutils.core import setup in setup.py to from setuptools import setup or refactor your setup.py to use only distutils features.

I came here because I hadn't realized entry_points was only a setuptools feature.

If you are here wanting to convert setuptools to distutils like me:

  1. remove install_requires from setup.py and just use requirements.txt with pip
  2. change entry_points to scripts (doc) and refactor any modules relying on entry_points to be full scripts with shebangs and an entry point.
1
  • I'm trying to understand what is the recommended package. You write "use only distutils features" also "convert setuptools to distutils", but also state "entry_points was only a setuptools feature", seems slightly contradictory? Oct 8, 2019 at 14:13
8

This is a warning from distutils, and is a sign that you do not have setuptools installed. Installing it from http://pypi.python.org/pypi/setuptools will remove the warning.

6
  • 35
    setuptools is installed. still has the warning.
    – Tyler Liu
    Nov 29, 2011 at 1:58
  • You are quite right, I get this error in Python 2.6.6 even if setuptools or distribute is installed. If I try with 2.7.2 it's gone though. Nov 29, 2011 at 9:32
  • 4
    I am having this problem in python 2.7.3 May 9, 2012 at 4:13
  • 2
    This did it for me: wget bootstrap.pypa.io/ez_setup.py -O - | sudo python
    – radtek
    Dec 30, 2014 at 5:34
  • Thank you, @radtek, that worked for me, too. Perhaps you could make your comment into an answer?
    – Esteis
    May 26, 2015 at 8:44
8
sudo apt-get install python-dev  # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

It will install any missing headers. It solved my issue

2
  • 1
    Using dnf install python39-devel.x86_64 in centOS8 solved the problem that I failed to install uwsgi
    – januw a
    Sep 27, 2021 at 6:07
  • This solved my issue. But on Amazon Linux 2023 I had to specify: sudo yum install python3-devel.x86_64
    – Drew S
    Jun 8 at 15:01
2

As far as I can tell, this is a bug in setuptools where it isn't removing the setuptools specific options before calling up to the base class in the standard library: https://bitbucket.org/pypa/setuptools/issue/29/avoid-userwarnings-emitted-when-calling

If you have an unconditional import setuptools in your setup.py (as you should if using the setuptools specific options), then the fact the script isn't failing with ImportError indicates that setuptools is properly installed.

You can silence the warning as follows:

python -W ignore::UserWarning:distutils.dist setup.py <any-other-args>

Only do this if you use the unconditional import that will fail completely if setuptools isn't installed :)

(I'm seeing this same behaviour in a checkout from the post-merger setuptools repo, which is why I'm confident it's a setuptools bug rather than a system config problem. I expect pre-merge distribute would have the same problem)

0

I've now seen this in legacy tools using Python2.7, where a build (like a Dockerfile) installs an unpinned dependancy, for example pytest. PyTest has dropped Python 2.7 support, so you may need to specify version < the new package release.

Or bite the bullet and convert that app to Python 3 if that is viable.

0

It works fine if you follow the official documentation:

import setuptools
setuptools.setup(...)

Source: https://packaging.python.org/tutorials/packaging-projects/#creating-setup-py

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.