Skip to content

Undeclared build dependency on cython #15298

Description

@jvesely

Description

pip install scikit-learn --no-binary :all: fails to install scikit because of missing cython build dependency. Once cython is installed manually the above command works and installs scikit-learn.

Steps/Code to Reproduce

pip install scikit-learn --no-binary :all:
it's also the case for python implementations that don't have scikit-learn wheels available (PyPy3, Python3.8)

Expected Results

scikit-learn installs successfully

Actual Results

  Running setup.py install for scikit-learn ... error
    Complete output from command /home/user/pypy3-venv/bin/pypy3-c -u -c "import setuptools, tokenize;__file__='/var/tmp/pip-install-zf4xear5/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/tmp/pip-record-k9u2qwff/install-record.txt --single-version-externally-managed --compile --install-headers /home/user/pypy3-venv/include/site/python3.6/scikit-learn:
    Partial import of sklearn during the build process.
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/var/tmp/pip-install-zf4xear5/scikit-learn/setup.py", line 290, in <module>
        setup_package()
      File "/var/tmp/pip-install-zf4xear5/scikit-learn/setup.py", line 286, in setup_package
        setup(**metadata)
      File "/home/user/pypy3-venv/site-packages/numpy/distutils/core.py", line 137, in setup
        config = configuration()
      File "/var/tmp/pip-install-zf4xear5/scikit-learn/setup.py", line 174, in configuration
        config.add_subpackage('sklearn')
      File "/home/user/pypy3-venv/site-packages/numpy/distutils/misc_util.py", line 1035, in add_subpackage
        caller_level = 2)
      File "/home/user/pypy3-venv/site-packages/numpy/distutils/misc_util.py", line 1004, in get_subpackage
        caller_level = caller_level + 1)
      File "/home/user/pypy3-venv/site-packages/numpy/distutils/misc_util.py", line 941, in _get_configuration_from_setup_py
        config = setup_module.configuration(*args)
      File "sklearn/setup.py", line 62, in configuration
        config.add_subpackage('utils')
      File "/home/user/pypy3-venv/site-packages/numpy/distutils/misc_util.py", line 1035, in add_subpackage
        caller_level = 2)
      File "/home/user/pypy3-venv/site-packages/numpy/distutils/misc_util.py", line 1004, in get_subpackage
        caller_level = caller_level + 1)
      File "/home/user/pypy3-venv/site-packages/numpy/distutils/misc_util.py", line 941, in _get_configuration_from_setup_py
        config = setup_module.configuration(*args)
      File "sklearn/utils/setup.py", line 8, in configuration
        from Cython import Tempita
    ModuleNotFoundError: No module named 'Cython'
    
    ----------------------------------------
Command "/home/user/pypy3-venv/bin/pypy3-c -u -c "import setuptools, tokenize;__file__='/var/tmp/pip-install-zf4xear5/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/tmp/pip-record-k9u2qwff/install-record.txt --single-version-externally-managed --compile --install-headers /home/user/pypy3-venv/include/site/python3.6/scikit-learn" failed with error code 1 in /var/tmp/pip-install-zf4xear5/scikit-learn/

Versions

Activity

  1. lesteve commented on Oct 19, 2019

    @lesteve
    Member

    Indeed I can reproduce.

    I seem to remember we included the .c files (generated from the Cython files) in the .tar.gz for source distribution (sdist). Maybe the problem is that we still go through the Cython route, even if we already have the .c files ... this needs to be double-checked.

  2. added this to the 0.22 milestone on Oct 22, 2019
  3. jvesely commented on Dec 9, 2019

    @jvesely
    ContributorAuthor

    Hi @rth, @lesteve,

    this issue still appears in 0.22. I think #15567 rendered changes in #15313 uneffective, and the cython dependency is still required.

    user@machine ~ $ python3 -m venv test-env
    user@machine ~ $ source test-env/bin/activate
    (test-env) user@machine ~ $ TMPDIR=/var/tmp/ pip3 install --no-binary :all: scikit-learn
    Collecting scikit-learn
      Using cached https://files.pythonhosted.org/packages/4f/2c/04e10167991ed6209fb251a212ca7c3148006f335f4aadf1808db2cbeda8/scikit-learn-0.22.tar.gz
    Collecting numpy>=1.11.0 (from scikit-learn)
      Using cached https://files.pythonhosted.org/packages/ff/59/d3f6d46aa1fd220d020bdd61e76ca51f6548c6ad6d24ddb614f4037cf49d/numpy-1.17.4.zip
    Collecting scipy>=0.17.0 (from scikit-learn)
      Using cached https://files.pythonhosted.org/packages/a7/5c/495190b8c7cc71977c3d3fafe788d99d43eeb4740ac56856095df6a23fbd/scipy-1.3.3.tar.gz
      Installing build dependencies ... done
    Collecting joblib>=0.11 (from scikit-learn)
      Using cached https://files.pythonhosted.org/packages/0a/ae/89d32b92903241468d9e993d05c49e8e7d58bdc3db51ed276b01786760ac/joblib-0.14.0.tar.gz
    Installing collected packages: numpy, scipy, joblib, scikit-learn
      Running setup.py install for numpy ... done
      Running setup.py install for scipy ... done
      Running setup.py install for joblib ... done
      Running setup.py install for scikit-learn ... error
        Complete output from command /home/user/test-env/bin/python3 -u -c "import setuptools, tokenize;__file__='/var/tmp/pip-install-r3bbyune/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/tmp/pip-record-wn_c4638/install-record.txt --single-version-externally-managed --compile --install-headers /home/user/test-env/include/site/python3.6/scikit-learn:
        Partial import of sklearn during the build process.
        Traceback (most recent call last):
          File "/var/tmp/pip-install-r3bbyune/scikit-learn/sklearn/_build_utils/__init__.py", line 32, in _check_cython_version
            import Cython
        ModuleNotFoundError: No module named 'Cython'
        
        During handling of the above exception, another exception occurred:
        
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/var/tmp/pip-install-r3bbyune/scikit-learn/setup.py", line 303, in <module>
            setup_package()
          File "/var/tmp/pip-install-r3bbyune/scikit-learn/setup.py", line 299, in setup_package
            setup(**metadata)
          File "/home/user/test-env/lib64/python3.6/site-packages/numpy/distutils/core.py", line 137, in setup
            config = configuration()
          File "/var/tmp/pip-install-r3bbyune/scikit-learn/setup.py", line 180, in configuration
            _check_cython_version()
          File "/var/tmp/pip-install-r3bbyune/scikit-learn/sklearn/_build_utils/__init__.py", line 35, in _check_cython_version
            raise ModuleNotFoundError(message)
        ModuleNotFoundError: Please install Cython with a version >= 0.28.5 in order to build a scikit-learn from source.
        
        ----------------------------------------
    Command "/home/user/test-env/bin/python3 -u -c "import setuptools, tokenize;__file__='/var/tmp/pip-install-r3bbyune/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/tmp/pip-record-wn_c4638/install-record.txt --single-version-externally-managed --compile --install-headers /home/user/test-env/include/site/python3.6/scikit-learn" failed with error code 1 in /var/tmp/pip-install-r3bbyune/scikit-learn/
    

    should I open a new issue, or can you reopen this one?

  4. rth commented on Dec 9, 2019

    @rth
    Member

    Thanks for reporting this!

    I think #15567 rendered changes in #15313 uneffective,

    Yes, makes sense.

  5. reopened this on Dec 9, 2019
  6. jeremiedbb commented on Dec 9, 2019

    @jeremiedbb
    Member

    I think #15567 rendered changes in #15313 uneffective, and the cython dependency is still required.

    Indeed, but we made cython a build dependency for scikit-learn. So from 0.22, if you pip install with the no-binary flag, you need cython.

  7. jvesely commented on Dec 9, 2019

    @jvesely
    ContributorAuthor

    I think #15567 rendered changes in #15313 uneffective, and the cython dependency is still required.

    Indeed, but we made cython a build dependency for scikit-learn. So from 0.22, if you pip install with the no-binary flag, you need cython.

    I understand that. It'd be nice if scikit-learn declared the build dependencies so that pip can install them automatically[0] rather than expecting the user to install it manually ahead of time.

    [0] https://packaging.python.org/specifications/declaring-build-dependencies/

  8. jeremiedbb commented on Dec 9, 2019

    @jeremiedbb
    Member

    We decided to not use pyproject.toml for this release because we didn't have time to test it properly before the release (you can see related discussion in #15567 and #15533). It's planed to add this for the next release

  9. jvesely commented on Dec 9, 2019

    @jvesely
    ContributorAuthor

    We decided to not use pyproject.toml for this release because we didn't have time to test it properly before the release (you can see related discussion in #15567 and #15533). It's planed to add this for the next release

    thanks! Those are both closed/merged. Is there an open issue/pr that tracks this?

  10. jeremiedbb commented on Dec 9, 2019

    @jeremiedbb
    Member

    Let's keep this one open to track this

  11. modified the milestones: 0.22, 0.22.1 on Dec 12, 2019
  12. adrinjalali commented on Dec 12, 2019

    @adrinjalali
    Member

    why is this a blocker for 0.22.1? Are we going to have a pyproject.toml? I think this takes a while to fix and we shouldn't block the bug-fix release because of it.

  13. jnothman commented on Dec 12, 2019

    @jnothman
    Member

    Sorry, didn't see it tagged blocker. When it was reopened it was tagged 0.22

  14. modified the milestones: 0.22.1, 0.23 on Dec 12, 2019
  15. adrinjalali commented on Dec 12, 2019

    @adrinjalali
    Member

    This also seems to be moving to the scipy org, which will make writing a pyproject.toml easier: https://pypi.org/project/oldest-supported-numpy/

  16. jackjansen commented on Dec 24, 2020

    @jackjansen

    I have the feeling this bug has re-appeared with release scikit-learn 0.24.

    As of a few days ago I see CI/CD builds failing for a project that has a deep indirect dependency on scikit-learn, with the ModuleNotFound error reported above. Sorry, I don't even know which package has the dependency on scikit-learn...

    I can tell you the CI/CD machine runs Python 3.6 on Ubuntu 18.04.

  17. adrinjalali commented on Dec 30, 2020

    @adrinjalali
    Member

    @jackjansen we'll need more context to re-open this issue. We do have a pyproject.toml file in which Cython is a declared build dependency, so I'm not sure what the issue is on your side.

  18. jackjansen commented on Dec 30, 2020

    @jackjansen

    @adrinjalali no need to reopen. The issue has been solved, see #19068.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions