133

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"?

tew
  • 2,723
  • 5
  • 23
  • 35
Tyler Liu
  • 19,552
  • 11
  • 100
  • 84
  • 1
    Possible duplicate of [Adding 'install\_requires' to setup.py when making a python package](https://stackoverflow.com/questions/9810603/adding-install-requires-to-setup-py-when-making-a-python-package) – tripleee Oct 02 '17 at 04:34
  • @tripleee maybe, but this question was asked earlier than that one. – Tyler Liu Oct 06 '17 at 10:06
  • [Question age is a secondary concern](https://meta.stackoverflow.com/questions/251938/should-i-flag-a-question-as-duplicate-if-it-has-received-better-answers) 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] 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 06 '17 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 08 '17 at 02:56
  • Please follow the official documentation and use `import setuptools; setuptools.setup()`. See: https://packaging.python.org/tutorials/packaging-projects/#creating-setup-py – guettli Sep 10 '20 at 20:19

10 Answers10

101

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.

Gringo Suave
  • 29,931
  • 6
  • 88
  • 75
Sebastian Blask
  • 2,870
  • 1
  • 16
  • 29
  • 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 '12 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.. – Sebastian Blask May 24 '12 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): https://bugs.pypy.org/issue878 – fiorix Jun 13 '12 at 08: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 02 '13 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. – Throw Away Account May 02 '19 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!

Matt
  • 691
  • 5
  • 2
  • This resolved it for me also. (Python 3.4, trying to `pip3 install neovim-remote`.) – Michael Iles Dec 10 '18 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 '19 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.

AlanSE
  • 2,597
  • 2
  • 29
  • 22
  • 1
    Adding ``import setuptools`` also miraculously resolved the issue for me on ubuntu 16.04 with python 3.5. – kuropan Jan 24 '19 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.

Community
  • 1
  • 1
PAStheLoD
  • 943
  • 12
  • 22
  • 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 04 '13 at 18:23
  • 1
    @Iguananaut, thanks for reviewing the answer; I've edited it. – PAStheLoD Jun 04 '13 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 05 '13 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 01 '19 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.
Karsten
  • 501
  • 6
  • 12
  • 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? – chrisinmtown Oct 08 '19 at 14:13
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

Priyanshu Chauhan
  • 5,297
  • 5
  • 35
  • 34
  • 1
    Using `dnf install python39-devel.x86_64` in centOS8 solved the problem that I failed to install `uwsgi` – januw a Sep 27 '21 at 06:07
  • This solved my issue. But on Amazon Linux 2023 I had to specify: `sudo yum install python3-devel.x86_64` – Drew S Jun 08 '23 at 15:01
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.

Fredrik Håård
  • 2,856
  • 1
  • 24
  • 32
  • 35
    setuptools is installed. still has the warning. – Tyler Liu Nov 29 '11 at 01: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. – Fredrik Håård Nov 29 '11 at 09:32
  • 4
    I am having this problem in python 2.7.3 – Calvin Cheng May 09 '12 at 04:13
  • 2
    This did it for me: wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python – radtek Dec 30 '14 at 05:34
  • Thank you, @radtek, that worked for me, too. Perhaps you could make your comment into an answer? – Esteis May 26 '15 at 08:44
  • I had this problem in python 2.7.6 when installing `setuptools` from source, after having `pip uninstall setuptools`. Instead, do `python setup.py install` for `setuptools` while `setuptools` is still installed. – 0 _ Jan 24 '16 at 23:43
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)

Alp
  • 29,274
  • 27
  • 120
  • 198
ncoghlan
  • 40,168
  • 10
  • 71
  • 80
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.

Danny Staple
  • 7,101
  • 4
  • 43
  • 56
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

guettli
  • 25,042
  • 81
  • 346
  • 663