Skip to content

MAINT Add python_requires>=3.5 to setup.py#13861

Merged
jnothman merged 3 commits intoscikit-learn:masterfrom
rth:fix-install-py2
May 13, 2019
Merged

MAINT Add python_requires>=3.5 to setup.py#13861
jnothman merged 3 commits intoscikit-learn:masterfrom
rth:fix-install-py2

Conversation

@rth
Copy link
Copy Markdown
Member

@rth rth commented May 10, 2019

Closes #13860

Marks the package as requiring python3.5+ in setup.py, so that it is not selected when istalled by pip from PyPi

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

Indeed I had thought about that an completely forgotten about it. 0.21.0.post0 is probably enough just for the tarball package. No need to change the wheels.

@rth
Copy link
Copy Markdown
Member Author

rth commented May 10, 2019

From https://packaging.python.org/guides/distributing-packages-using-setuptools/,

Support for this feature is relatively recent. Your project’s source distributions and wheels (see Packaging your project) must be built using at least version 24.2.0 of setuptools in order for the python_requires argument to be recognized and the appropriate metadata generated.

In addition, only versions 9.0.0 and higher of pip recognize the python_requires metadata. Users with earlier versions of pip will be able to download & install projects on any Python version regardless of the projects’ python_requires values.

I think it should be fine. Another this is I'm not sure we should actually fail explicitly in setup.py on python2 or not.

@ogrisel ogrisel mentioned this pull request May 10, 2019
@rth
Copy link
Copy Markdown
Member Author

rth commented May 10, 2019

I think this should fix it, but it would be good if someone could double check.

0.21.0.post0 is probably enough just for the tarball package.

Right, if one can remove just one file from PyPy without removing the release that could work.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

We can check locally by:

  • changing the version number to 0.21.0.post0 (+ your fix)
  • building the sdist
  • create a new empty venv for python 2.7
  • pip install -U -f /path/to/dist/folder scikit-learn

It should ignore the local tarball and install the latest python 2.7 compatible wheel (scikit-learn 0.20.3) from PyPI.

The same command from an empty python 3 venv should install from the local sdist.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

Hum, that might not be enough:

(py2tmp) ogrisel@ici:~/code/scikit-learn/dist$ pip install -U -f . scikit-learn
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in links: .
Collecting scikit-learn
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-1B7AMh/scikit-learn/setup.py", line 30, in <module>
        % (platform.python_version(), sys.executable))
    RuntimeError: Scikit-learn requires Python 3.5 or later. The current Python version is 2.7.16 installed in /home/ogrisel/miniconda3/envs/py2tmp/bin/python.
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-1B7AMh/scikit-learn/

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

Actually my test is probably not doing what it's supposed to do and is probably not going to work as long as the broken tarball is the most recent tarball uploaded on pypi.org ...

We might need to delete the 0.21.0 source dist from pypi.org

@rth
Copy link
Copy Markdown
Member Author

rth commented May 10, 2019

We might need to delete the 0.21.0 source dist from pypi.org

I also think so #13860 (comment)

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

I will push a fix to your PR soon (to remove the numpy / python 3 dependency just to get egg_info).

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

If you try to pip install a tarball generated with the setup.py from this PR in a python 2.7 environment, you will get the expected error message:

ERROR: scikit-learn requires Python '>=3.5' but the running Python is 2.7.16

generated by pip's own check_dist_requires_python function which seems correct to me.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

To get more details in your tests you can do:

cd dist/
pip install -v --no-cache -U -f file://$PWD scikit-learn

Unfortunately it does not seem to fallback to the online PyPI index but it's probably expected when using -f on a local folder. So I am not sure how to test the full things without making a new sdist release (0.21.0.post0) on PyPI (and deleting the 0.21.0 tarball from PyPI).

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

I just deleted the 0.20.0 tarball from PyPI to avoid causing this problem to python 2 users and CI servers around the world while we are fixing the metadata.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 10, 2019

A better long term solution that does not involve keeping Python 2 compat for the python setup.py egg_info command might be to include a pyproject.toml file in our tarball with all the necessary metadata.

I am not sure how to do that without introducing too much redundancy so better keep that for the next release.

Copy link
Copy Markdown
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not tested but this lgtm

@jnothman jnothman merged commit 2a1e968 into scikit-learn:master May 13, 2019
jnothman pushed a commit to jnothman/scikit-learn that referenced this pull request May 14, 2019
* Add python_requires to setup.py
* FIX make it possible to run egg_info from Python 2 without numpy
* Informative error message for python2.7 setup.py install (without breaking python2.7 setup.py egg_info)
jnothman pushed a commit to jnothman/scikit-learn that referenced this pull request May 14, 2019
* Add python_requires to setup.py
* FIX make it possible to run egg_info from Python 2 without numpy
* Informative error message for python2.7 setup.py install (without breaking python2.7 setup.py egg_info)
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
* Add python_requires to setup.py
* FIX make it possible to run egg_info from Python 2 without numpy
* Informative error message for python2.7 setup.py install (without breaking python2.7 setup.py egg_info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pip install scikit-learn fails on python 2

3 participants