Skip to content

Register build-time dependencies in the setup.py as a setup_requirement. #7867

Closed
@HolgerPeters

Description

@HolgerPeters

I package Python packages as wheels using the pip wheel command. Scikit-learn does not report its requirements to setuptools as install_requires or setup_requires. This makes pip wheel fail.

Description

The current checks for the presence of numpy and scipy during installation is according to what I found in the repo and the tracker based on Issue #1495 and PR #4371.

I suggest to avoid raising errors in setup.py and list numpy as an setup requirement and numpy and scipy as an install requirement, so that pip/wheel can install the dependencies seamlessly in the background, if they are not present. Pip's setup_requires section should list all packages necessary to invoke setup.py subbcommands (http://setuptools.readthedocs.io/en/latest/setuptools.html#setup_requires).

In my usage example, pip wheel would install numpy then temporarily for the creation of the scikit-learn wheel.

Steps/Code to Reproduce

virtualenv sklearntest
. sklearntest/bin/activate
pip install -U pip setuptools wheel
pip wheel --no-binary :all: scikit-learn

Expected Results

A scikit-learn wheel should be buildable as simple as

% pip install scikit-learn
Processing /whatever-dir/devel/scikit-learn
Collecting numpy (from scikit-learn==0.19.dev0)
  File was already downloaded /whatever-dir/devel/scikit-learn/numpy-1.11.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting scipy (from scikit-learn==0.19.dev0)
  File was already downloaded /whatever-dir/devel/scikit-learn/scipy-0.18.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
[..............]
Successfully built scikit-learn
pip wheel .  87.87s user 9.66s system 76% cpu 2:07.13 total

Actual Results

Collecting scikit-learn
  Downloading scikit-learn-0.18.1.tar.gz (8.9MB)
    100% |################################| 8.9MB 143kB/s 
Building wheels for collected packages: scikit-learn
  Running setup.py bdist_wheel for scikit-learn ... error
  Complete output from command /private/tmp/sklearntest/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/kn/3fznwwr15z9chdd30p3q4qm80000gp/T/pip-build-489cEa/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /var/folders/kn/3fznwwr15z9chdd30p3q4qm80000gp/T/tmpMCqZC2pip-wheel-:
  Partial import of sklearn during the build process.
  Traceback (most recent call last):
    File "/private/var/folders/kn/3fznwwr15z9chdd30p3q4qm80000gp/T/pip-build-489cEa/scikit-learn/setup.py", line 169, in get_numpy_status
      import numpy
  ImportError: No module named numpy
  Traceback (most recent call last):
    File "/private/var/folders/kn/3fznwwr15z9chdd30p3q4qm80000gp/T/pip-build-489cEa/scikit-learn/setup.py", line 149, in get_scipy_status
      import scipy
  ImportError: No module named scipy
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/private/var/folders/kn/3fznwwr15z9chdd30p3q4qm80000gp/T/pip-build-489cEa/scikit-learn/setup.py", line 270, in <module>
      setup_package()
    File "/private/var/folders/kn/3fznwwr15z9chdd30p3q4qm80000gp/T/pip-build-489cEa/scikit-learn/setup.py", line 250, in setup_package
      .format(numpy_req_str, instructions))
  ImportError: Numerical Python (NumPy) is not installed.
  scikit-learn requires NumPy >= 1.6.1.
  Installation instructions are available on the scikit-learn website: http://scikit-learn.org/stable/install.html

Discussion

The nature of my request is basically, to make scikit-learn behave more closely to how other packages behave.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions