Skip to content

can't setup.py install without numpy #4164

Closed

Description

@bukzor

At minimum, this could use a better error message. Is it not possible to have a project that depends on sklearn and installs all its dependencies to a virtualenv in a single pass? Must I do one pass to install numpy and everything else, and a second pass just to install sklearn?

$ python setup.py install
Partial import of sklearn during the build process.
Traceback (most recent call last):
  File "setup.py", line 154, in <module>
    setup_package()
  File "setup.py", line 146, in setup_package
    from numpy.distutils.core import setup
ImportError: No module named numpy.distutils.core

Activity

  1. amueller commented on Jan 26, 2015

    @amueller
    Member

    What is your current install setup? Scikit-learn requires numpy and if you install everything together, it should work fine.

  2. GaelVaroquaux commented on Jan 26, 2015

    @GaelVaroquaux
    Member

    At minimum, this could use a better error message.

    Agreed.

    Is it not possible to have a project that depends on sklearn and
    installs all its dependencies to a virtualenv in a single pass?

    How are you installing things? If you are compiling from source, you do
    need numpy installed.

    Must I do one pass to install numpy and everything else, and a second
    pass just to install sklearn?

    I would be surprised that scipy behaves different.

  3. GaelVaroquaux commented on Jan 26, 2015

    @GaelVaroquaux
    Member

    Scipy does behave differently:
    https://github.com/scipy/scipy/blob/master/setup.py#L190

    Hum, interesting.

    There are pros and cons for doing it this way for numpy. The pro is that
    it probably solves the OPs problem. The con is that more people are going
    to be hand compiling numpy instead of installing good packages, and thus
    be left with horrible linear algebra package.

    My hunch would be to leave it the way it is, but I see the point of the
    clever trick used in scipy's setup.py.

  4. bukzor commented on Jan 26, 2015

    @bukzor
    Author

    Demo:

    rm -rf fresh
    virtualenv fresh
    . fresh/bin/activate
    
    # pip 6 reverses order of "top-level" requirements -.-
    #   https://github.com/pypa/pip/issues/2260
    pip install --upgrade pip
    
    echo >requirements.txt 'numpy
    scikit-learn'
    pip install  -r requirements.txt
    

    output:

    $ sh demo.sh
    New python executable in fresh/bin/python
    Installing setuptools, pip...done.
    Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-6.0.6-py2.py3-none-any.whl#md5=0472d9dc76a0df6cc6ab545e40aef832
      Downloading pip-6.0.6-py2.py3-none-any.whl (1.3MB): 1.3MB downloaded
    Installing collected packages: pip
      Found existing installation: pip 1.5.6
        Uninstalling pip:
          Successfully uninstalled pip
    Successfully installed pip
    Cleaning up...
    Collecting numpy (from -r requirements.txt (line 1))
      Using cached numpy-1.9.1.tar.gz
        Running from numpy source directory.
    Collecting scikit-learn (from -r requirements.txt (line 2))
      Using cached scikit-learn-0.15.2.tar.gz
        Partial import of sklearn during the build process.
    Installing collected packages: scikit-learn, numpy
      Running setup.py install for scikit-learn
        Partial import of sklearn during the build process.
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/nail/tmp/pip-build-oylnbV/scikit-learn/setup.py", line 154, in <module>
            setup_package()
          File "/nail/tmp/pip-build-oylnbV/scikit-learn/setup.py", line 146, in setup_package
            from numpy.distutils.core import setup
        ImportError: No module named numpy.distutils.core
        Complete output from command /nail/home/buck/tmp/fresh/bin/python -c "import setuptools, tokenize;__file__='/nail/tmp/pip-build-oylnbV/scikit-learn/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /nail/tmp/pip-x4l77V-record/install-record.txt --single-version-externally-managed --compile --install-headers /nail/home/buck/tmp/fresh/include/site/python2.6:
        Partial import of sklearn during the build process.
    
        Traceback (most recent call last):
    
          File "<string>", line 1, in <module>
    
          File "/nail/tmp/pip-build-oylnbV/scikit-learn/setup.py", line 154, in <module>
    
            setup_package()
    
          File "/nail/tmp/pip-build-oylnbV/scikit-learn/setup.py", line 146, in setup_package
    
            from numpy.distutils.core import setup
    
        ImportError: No module named numpy.distutils.core
    
        ----------------------------------------
        Command "/nail/home/buck/tmp/fresh/bin/python -c "import setuptools, tokenize;__file__='/nail/tmp/pip-build-oylnbV/scikit-learn/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /nail/tmp/pip-x4l77V-record/install-record.txt --single-version-externally-managed --compile --install-headers /nail/home/buck/tmp/fresh/include/site/python2.6" failed with error code 1 in /nail/tmp/pip-build-oylnbV/scikit-learn
    
  5. GaelVaroquaux commented on Jan 26, 2015

    @GaelVaroquaux
    Member

    Maybe we could make this demo work, but chances are that you would have a
    really lousy install of numpy and scikit-learn. The problem is that numpy
    wouldn't be linked to good linear algebra packages, unless you know what
    you are doing, and you have installed the headers of these before. But
    that last operation is much harder than getting the pip/python part right.

    Really, you should be building from source only if you know well what you
    do. In which case none of this should be a problem.

    If you are not an expert, please use prebuild packages. At least this is
    my opinion.

  6. amueller commented on Jan 26, 2015

    @amueller
    Member

    You are right, installing this way really is a bad idea in most cases...

  7. douardda commented on Mar 3, 2015

    @douardda

    This is a serious issue, since virtualenv and pip are really becoming the standard to set up a test or development environment.

    How can I run tox-based contiuous integration tests for projects that depend on sklearn then?

    I agree that using prebuilt packages provided by a decent Linux distribution is the way for production/real life applications, but CI and automatic tests are required tools too.

    scikit-learn should not be installed using "pip install" or setuptools in general, but scikit-learn must be installable that way.

    David

  8. amueller commented on Mar 3, 2015

    @amueller
    Member

    Hum, continuous integration is a good point.
    However, the value of the integration is not that high if your production setup is quite different from your CI setup....

  9. amueller commented on Mar 3, 2015

    @amueller
    Member

    @douardda can you try if the scipy hack works for you?
    That is

    try:
        import numpy
    except:
        build_requires = ['numpy>=1.6.2']
    

    But I guess it will be more complicated than that...

  10. amueller commented on Mar 3, 2015

    @amueller
    Member

    Hum, our setup.py seems pretty identical to the scipy one, I'm not sure what makes theirs work.

  11. douardda commented on Mar 4, 2015

    @douardda

    Humm, on my jessie laptop, in a fresh virtualenv, "pip install scipy" also fails with a "ImportError: No module named numpy.distutils.core".

  12. added a commit that references this issue on Mar 4, 2015
    eab4f7c
  13. saketkc commented on Mar 4, 2015

    @saketkc
    Contributor

    @douardda Would you want to test out the patch in #4332?

  14. 11 remaining items

  15. amueller commented on May 9, 2015

    @amueller
    Member

    I agree that if that is how you produce production binaries, then you are most certainly doing it wrong.
    Though I don't agree with @GaelVaroquaux that scikit-learn should tell you which scipy to use. I feel it's scipy's responsibility to make sure scipy is installed in a sane way.

  16. taion commented on Jan 14, 2016

    @taion
    Contributor

    What do you think of using extras_require to make available something like a scikit-learn[pip] that actually includes numpy and scipy under install_requires?

    This would preserve the current behavior for most users, but would allow people using a standard virtualenv/pip toolchain to have a way to set up environments including scikit-learn without having to jump through a large number of hoops.

    cc @cancan101

  17. amueller commented on Jan 15, 2016

    @amueller
    Member

    I think that would be fine.

  18. Raji25 commented on Mar 3, 2016

    @Raji25

    from numpy.distutils.core import setup
    ImportError: No module named 'numpy'

    what have to be done in order to rectify the error?

  19. timabbott commented on Jul 7, 2016

    @timabbott

    Any progress on this issue? It'd be really great if there was a way to use scikit-learn inside a virtualenv by including it (and whatever versions of numpy/scipy/etc. one wants) in a requirements.txt file. Virtualenvs are a very standard way to deploy applications these days, so this is a pretty common use case.

    Since there was a solution under discussion as of a few months ago, maybe it makes sense to reopen the issue at least?

  20. taion commented on Jul 7, 2016

    @taion
    Contributor

    I never got a chance to work on this. I still think it should be possible/straightforward to set up a scikit-learn[pip] extra that has the right dependencies, especially now that pip-tools properly supports extras.

  21. matt-carter commented on Jul 14, 2016

    @matt-carter

    Seconding @timabbott.

  22. taion commented on Jul 14, 2016

    @taion
    Contributor

    PR up at #6990. It's a very straightforward change.

  23. eligiblekeng commented on Aug 29, 2016

    @eligiblekeng

    Temporary fix by overriding the install command in setup.py:

    import pip
    from setuptools import setup
    from setuptools.command.install import install
    from pip.req import parse_requirements
    install_reqs = parse_requirements('./requirements.txt', session=False)
    reqs = [str(ir.req) for ir in install_reqs]
    
    
    class OverrideInstall(install):
    
        """
        Emulate sequential install of pip install -r requirements.txt
        To fix numpy bug in scipy, scikit in py2
        """
    
        def run(self):
            for req in reqs:
                pip.main(["install", req])
    
    
    
    # the setup
    setup(
        ...
        cmdclass={'install': OverrideInstall}
        ....
    )

    Then run python setup.py install as usual

  24. added a commit that references this issue on Sep 30, 2020
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions