Skip to content

ImportError: no module named 'numpy' #1639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rkingsbury opened this issue Sep 10, 2015 · 14 comments
Closed

ImportError: no module named 'numpy' #1639

rkingsbury opened this issue Sep 10, 2015 · 14 comments

Comments

@rkingsbury
Copy link

The builds for my project started failing a few weeks ago even though I have made no changes to my setup.py, conf.py, requirements.txt, or RTFD configuration. I'm building in a virtualenv, and the only thing listed in requirements.txt is 'numpydoc'. My project depends on the scipy and pint packages, which are included in setup.py.

Here is a partial log for the failure. It seems that scipy is pulling in numpy as a dependency, and that's when the failure occurs.


Installed /home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/pyEQL-0.3.dev0-py3.4.egg
Processing dependencies for pyEQL==0.3.dev0
Searching for scipy
Reading https://pypi.python.org/simple/scipy/
Best match: scipy 0.16.0
Downloading https://pypi.python.org/packages/source/s/scipy/scipy-0.16.0.zip#md5=1764bd452a72698b968ad13e51e28053
Processing scipy-0.16.0.zip
Writing /tmp/easy_install-7317tphv/scipy-0.16.0/setup.cfg
Running scipy-0.16.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-7317tphv/scipy-0.16.0/egg-dist-tmp-_z_ta2_w
Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 152, in save_modules
    yield saved
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 193, in setup_context
    yield
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 237, in run_setup
    DirectorySandbox(setup_dir).run(runner)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 267, in run
    return func()
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 236, in runner
    _execfile(setup_script, ns)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 46, in _execfile
    exec(code, globals, locals)
  File "/tmp/easy_install-7317tphv/scipy-0.16.0/setup.py", line 253, in <module>
  File "/tmp/easy_install-7317tphv/scipy-0.16.0/setup.py", line 241, in setup_package
ImportError: No module named 'numpy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 88, in <module>
    'pyEQL=pyEQL:main',
  File "/usr/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/install.py", line 117, in do_egg_install
    cmd.run()
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 380, in run
    self.easy_install(spec, not self.no_deps)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 610, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 661, in install_item
    self.process_distribution(spec, dist, deps)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 709, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/pkg_resources/__init__.py", line 836, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/pkg_resources/__init__.py", line 1081, in best_match
    return self.obtain(req, installer)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/pkg_resources/__init__.py", line 1093, in obtain
    return installer(requirement)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 629, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 659, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 842, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 1070, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 1056, in run_setup
    run_setup(setup_script, args)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 240, in run_setup
    raise
  File "/usr/lib/python3.4/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 193, in setup_context
    yield
  File "/usr/lib/python3.4/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 164, in save_modules
    saved_exc.resume()
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 139, in resume
    compat.reraise(type, exc, self._tb)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/compat.py", line 65, in reraise
    raise value.with_traceback(tb)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 152, in save_modules
    yield saved
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 193, in setup_context
    yield
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 237, in run_setup
    DirectorySandbox(setup_dir).run(runner)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 267, in run
    return func()
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 236, in runner
    _execfile(setup_script, ns)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/setuptools/sandbox.py", line 46, in _execfile
    exec(code, globals, locals)
  File "/tmp/easy_install-7317tphv/scipy-0.16.0/setup.py", line 253, in <module>
  File "/tmp/easy_install-7317tphv/scipy-0.16.0/setup.py", line 241, in setup_package
ImportError: No module named 'numpy'
@gregmuellegger
Copy link
Contributor

Unfortunately we cannot support to install numpy directly into a virtualenv as we can't support compiling C libraries. However numpy is installed globally on our buildservers, so you should be able to satisfy your requirements by allowing the virtualenv access to the system site packages.

To do so, go to the Advanced settings section in your project's admin panel and select the checkbox in Use system packages.

@gregmuellegger gregmuellegger added the Support Support question label Sep 10, 2015
@rkingsbury
Copy link
Author

@gregmuellegger thank you for the explanation. However, I tried enabling that option and the build still failed. Also, this wouldn't explain why the build was originally working and then started failing a few weeks ago (unless scipy recently added numpy as a dependency, but I think it's been that way for a while...).

Can you think of anything else that might be causing this?

@gregmuellegger
Copy link
Contributor

Hm, I'm no 100% sure but based on this comment (from 2012) it's not possible to use numpy/scipy combined with a virtualenv. However that seems little strange to me.

Maybe can @ericholscher or @agjohnson shed some light on what the current situation looks like? Is it possible to use the system numpy/scipy with a virtualenv?

@agjohnson
Copy link
Contributor

It should be, I just debugged a project making use of scipy/numpy without any errors. Not sure what the case is here exactly though.

@gregmuellegger
Copy link
Contributor

Hm, it might be failing since we don't have numpy for Python 3 installed on the server.
Related #1131

@gregmuellegger
Copy link
Contributor

Hooray, it's fixed. @rkingsbury your builds are passing again: https://readthedocs.org/projects/pyeql/builds/3330459/

@rkingsbury
Copy link
Author

Great, thanks for your attention to this @gregmuellegger

@uvchik
Copy link

uvchik commented Sep 23, 2015

I have the same problems, using scipy in my project. Now I solved the numpy issue by installing it separately but RTD is still not able to install scipy.

error: no lapack/blas resources found

https://readthedocs.org/projects/feedinlib/builds/3346237/

On my ubuntu maschine I solved the problems with scipy installing the following packages:

sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev gfortran

I tried it with python2 and python3.

The odd thing is that the pyeql projects now compiles with scipy successfully. Even though they also had problems in the past (e.g. pysql).

It failed on Sept. 10, 2015.
https://readthedocs.org/projects/pyeql/builds/3313638/

  File "/tmp/easy_install-iatx16tf/scipy-0.16.0/setup.py", line 253, in <module>
  File "/tmp/easy_install-iatx16tf/scipy-0.16.0/setup.py", line 241, in setup_package
ImportError: No module named 'numpy'

But worked on Sept. 17, 2015
https://readthedocs.org/projects/pyeql/builds/3330459/

Installed /home/docs/checkouts/readthedocs.org/user_builds/pyeql/envs/latest/lib/python3.4/site-packages/Pint-0.6-py3.4.egg
Searching for scipy==0.13.3
Best match: scipy 0.13.3
Adding scipy 0.13.3 to easy-install.pth file

@gregmuellegger
Copy link
Contributor

@uvchik the reason it works now for pyeql is that we have added numpy and scipy for the Python 3 projects and pyeql is one of them.

I assume that your build fails as it tries to manually install numpy as it is listed as requirement in your setup.py file: https://github.com/oemof/feedinlib/blob/master/setup.py#L30

You might want to exclude numpy from your dependencies when building on readthedocs. You can test for the READTHEDOCS environment variable which will be set during the build on readthedocs.org

@DavidLP
Copy link

DavidLP commented Nov 16, 2016

So, time has passed and numpy / scipy are now available as binary packages on pypi and install just fine with the READTHEDOCS virtual environment.
Unfortunately additional modules are not able to recognize these packages. My output:

Collecting numpy (from -r /home/docs/checkouts/readthedocs.org/user_builds/scarce/checkouts/latest/requirements.txt (line 1))
/home/docs/checkouts/readthedocs.org/user_builds/scarce/envs/latest/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/home/docs/checkouts/readthedocs.org/user_builds/scarce/envs/latest/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached numpy-1.11.2-cp27-cp27mu-manylinux1_x86_64.whl
Collecting scipy (from -r /home/docs/checkouts/readthedocs.org/user_builds/scarce/checkouts/latest/requirements.txt (line 2))
  Using cached scipy-0.18.1-cp27-cp27mu-manylinux1_x86_64.whl
Collecting pygmsh (from -r /home/docs/checkouts/readthedocs.org/user_builds/scarce/checkouts/latest/requirements.txt (line 3))
  Using cached pygmsh-2.4.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-zui5Yp/pygmsh/setup.py", line 7, in <module>
        from pygmsh import __name__, __version__, __author__, __author_email__
      File "pygmsh/__init__.py", line 8, in <module>
        from pygmsh.geometry import Geometry
      File "pygmsh/geometry.py", line 12, in <module>
        import numpy
    ImportError: No module named numpy

Any suggestions?

@jjgomera
Copy link

jjgomera commented Nov 1, 2017

Hi,
same problem here, scipy installed but other packages can't recognize installed dependence:

Collecting scipy (from -r requirements_docs.txt (line 1))
  Downloading scipy-1.0.0-cp35-cp35m-manylinux1_x86_64.whl (49.6MB)
Collecting numpy (from -r requirements_docs.txt (line 2))
  Downloading numpy-1.13.3-cp35-cp35m-manylinux1_x86_64.whl (16.9MB)
Collecting numpydoc (from -r requirements_docs.txt (line 3))
  Downloading numpydoc-0.7.0.tar.gz
Collecting pyqt5 (from -r requirements_docs.txt (line 4))
  Downloading PyQt5-5.9-5.9.1-cp35.cp36.cp37-abi3-manylinux1_x86_64.whl (104.6MB)
Collecting matplotlib (from -r requirements_docs.txt (line 5))
  Downloading matplotlib-2.1.0-cp35-cp35m-manylinux1_x86_64.whl (15.0MB)
Collecting iapws (from -r requirements_docs.txt (line 6))
  Downloading iapws-1.2.tar.gz (104kB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-o8yqdn26/iapws/setup.py", line 3, in <module>
        from iapws import __version__
      File "/tmp/pip-build-o8yqdn26/iapws/iapws/__init__.py", line 5, in <module>
        from ._iapws import (_Ice, _Sublimation_Pressure, _Melting_Pressure,  # noqa
      File "/tmp/pip-build-o8yqdn26/iapws/iapws/_iapws.py", line 13, in <module>
        from scipy.optimize import minimize
    ImportError: No module named 'scipy'

@RichardLitt RichardLitt reopened this Nov 1, 2017
@agjohnson
Copy link
Contributor

Both of these packages are referencing scipy/numpy after collection and before installation. These packages look to be both trying to import themselves before full installation -- iapws looks to be trying to get the version from the package. This is incorrect packaging behavior as dependencies aren't installed yet. There doesn't seem to be much we can do here, you'd have more luck bringing up the issue with the package maintainers.

@agjohnson agjohnson removed the Support Support question label Nov 1, 2017
@jjgomera
Copy link

jjgomera commented Nov 1, 2017

I can solve my problem checking the Give the virtual environment access to the global site-packages dir options. In thats case I ask if I must delete numpy/scipy dependences from requirement_docs.txt.

Thanks for answer

@mukaddesau
Copy link

You should use $pip install numpy instead of $pip3 install numpy after you activate virtual environment. It's just because your vir env already knows that you are using the version of python 3.

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

No branches or pull requests

8 participants