Skip to content
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

numpy not importing in python3.7 virtualenv #14676

Closed
dpk9 opened this issue Oct 10, 2019 · 12 comments
Closed

numpy not importing in python3.7 virtualenv #14676

dpk9 opened this issue Oct 10, 2019 · 12 comments
Labels
32 - Installation Problems installing or compiling NumPy

Comments

@dpk9
Copy link

dpk9 commented Oct 10, 2019

Reproducing code example:

import numpy

Error message:

Traceback (most recent call last):
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/core/__init__.py", line 17, in <module>
    from . import multiarray
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/core/multiarray.py", line 14, in <module>
    from . import overrides
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main_commandline.py", line 7, in <module>
    import numpy as np
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/core/__init__.py", line 47, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.7 from "/home/pi/.virtualenvs/print3.7/bin/python",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.17.2" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory

Numpy/Python version information:

>>> import sys, numpy; print(numpy.__version__, sys.version)
Traceback (most recent call last):
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/core/__init__.py", line 17, in <module>
    from . import multiarray
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/core/multiarray.py", line 14, in <module>
    from . import overrides
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/home/pi/.virtualenvs/print3.7/lib/python3.7/site-packages/numpy/core/__init__.py", line 47, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.7 from "/home/pi/.virtualenvs/print3.7/bin/python",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.17.2" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory

Info that the error message requested:

 - how you installed Python: Python3.7 comes pre-installed with Raspbian Buster. Made a virtualenv using 3.7
 - how you installed numpy: In my venv, `pip3 install numpy`
 - your operating system: Raspbian Buster, apt-get updated and upgraded.
 - whether or not you have multiple versions of Python installed: 2.7 and 3.7 by default.  Added 3.6 myself (sudo apt-get install python3.6-dev) but am not using it for this.
@mattip
Copy link
Member

mattip commented Oct 10, 2019

Please see #11110, where the solution was to sudo pip uninstall numpy; sudo apt install python3-numpy

@dpk9
Copy link
Author

dpk9 commented Oct 15, 2019

This did not work for me.

  • The linux distro already has numpy installed via apt:
    $ sudo apt install python3-numpy
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    python3-numpy is already the newest version (1:1.16.2-1).
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    Again, when I'm not in a virtualenv, I can import numpy. It's when I'm in a virtualenv that I have an issue (same python version in the venv as when deactivated).
  • Since I'm trying to do this in a virtualenv, the numpy I'm trying to use is located inside the venv's site-packages folder, not the main python installation or wherever apt installs it to.
  • I can't uninstall numpy from pip(3) outside of the venv because it's installed via apt instead of pip.
  • Inside the venv, I can do pip uninstall numpy but that doesn't help me because it's a venv.

@dpk9
Copy link
Author

dpk9 commented Oct 16, 2019

What I did to make it work was create a virtual env with the --system-site-packages option, so it inherited the working systemwide numpy. Then all the other modules I need specific to the environment can be installed with pip as usual. If there are any other system modules (i.e. 'foo') that I want to have inside the environment, pip install -I foo will re-install the module inside the environment (pip install foo will not work because it's already been satisfied by the system site package).

I don't think this is the best way to do things, but it'll do for now.

@rgommers rgommers added the 32 - Installation Problems installing or compiling NumPy label Dec 3, 2019
@EdwardChamberlain
Copy link

I also had this issue. For me running sudo apt-get install libatlas-base-dev fixed it. It seems this is an issue with piwheels.

@PJMF
Copy link

PJMF commented May 1, 2020

That worked for me .....

@oktep
Copy link

oktep commented May 8, 2020

Worked sudo apt-get install libatlas-base-dev for me

@mattip
Copy link
Member

mattip commented May 8, 2020

Closing. Glad this solves the problem.

@mattip mattip closed this as completed May 8, 2020
@Danie12345
Copy link

Danie12345 commented Dec 1, 2022

Getting a ModuleNotFoundError: No module named 'numpy' error in windows. Newly set up venv, and installed numpy via pip onto the venv.
I'm using vscode so when I ctrl+click the module's name it redirects me to the __init__.py of numpy in my venv. No idea why it doesn't work during runtime.

EDIT: For anyone facing the same issue, try running the file without using the terminal. I used a button from the Python intellisense extension I have installed and it seemed to work.

@mattip
Copy link
Member

mattip commented Dec 1, 2022

The long error message should help you debug the problem, which is probably caused by installing numpy with one interpreter and running with another.

@Danie12345
Copy link

The long error message should help you debug the problem, which is probably caused by installing numpy with one interpreter and running with another.

I did not get a long stack of errors. Only that and the line in my file where the trace started. I will add that having the venv selected is not enough, so it may be a vscode problem.

@mattip
Copy link
Member

mattip commented Dec 1, 2022

Either someone is catching the import error and reformatting it so you don't see the error we carefully craft to handle this kind of situation, or the python you are running (try running import sys; print(sys;executable) in VSCode) is not at all the one you want.

@Danie12345
Copy link

I believe it was just one of those situations where the selected environment was not being used. And running that piece of code confirms it. I've managed to get around it by running the file with a button, which finds the file and runs it using the selected environment for me.

Sorry for the trouble, and thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
32 - Installation Problems installing or compiling NumPy
Projects
None yet
Development

No branches or pull requests

7 participants