1

I manage a group of users so I'm trying to figure out how I can install numpy for all of them to use without having everyone install the package themselves.

I have Python 2.7.17 and Python 3.6.9 (installed by default through Ubuntu 18.04). Additionally, I have installed Python 3.7.5, Python 3.8.0, and numpy using the following.

sudo apt install python3.7
sudo apt install python3.8
sudo apt install python3-numpy

If I run python or python3 or python3.6 which (invokes python 2.7.17 or python 3.6.9), I can run the following command just fine.

import numpy

However, if I try to run the above after running python3.7 or python3.8 I get the following error message:

ImportError: cannot import name 'multiarray' from 'numpy.core' (/usr/lib/python3/dist-packages/numpy/core/__init__.py)

EDIT: Full error

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 16, in <module>
    from . import multiarray
ImportError: cannot import name 'multiarray' from 'numpy.core' (/usr/lib/python3/dist-packages/numpy/core/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError: 
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name 'multiarray' from 'numpy.core' (/usr/lib/python3/dist-packages/numpy/core/__init__.py)

When I install numpy it gets installed to /usr/lib/python3/dist-packages which should be fine since it's on the sys.path() for all versions of Python.

Could it not be working because the version of numpy being pulled using apt is only for Python 3.6.9? If that's the case, how should I install numpy for all users for ALL versions of Python?

EDIT 2: Contents of /usr/lib/python3/dist-packages/numpy/core

total 3672
-rw-r--r-- 1 root root   29215 Sep 29  2017 arrayprint.py
-rw-r--r-- 1 root root     413 Sep 17  2017 cversions.py
-rw-r--r-- 1 root root   67393 Sep 17  2017 defchararray.py
-rw-r--r-- 1 root root    6208 Dec  5  2017 _dummy.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 root root   35533 Sep 29  2017 einsumfunc.py
-rw-r--r-- 1 root root   98980 Sep 29  2017 fromnumeric.py
-rw-r--r-- 1 root root   12104 Sep 29  2017 function_base.py
-rw-r--r-- 1 root root    7331 Sep 29  2017 generate_numpy_api.py
-rw-r--r-- 1 root root   18422 Sep 17  2017 getlimits.py
drwxr-xr-x 3 root root    4096 Mar 24 13:20 include
-rw-r--r-- 1 root root    4692 Sep 17  2017 info.py
-rw-r--r-- 1 root root    3039 Sep 29  2017 __init__.py
-rw-r--r-- 1 root root   21375 Sep 29  2017 _internal.py
drwxr-xr-x 3 root root    4096 Mar 24 13:20 lib
-rw-r--r-- 1 root root   10789 Sep 17  2017 machar.py
-rw-r--r-- 1 root root   11432 Sep 17  2017 memmap.py
-rw-r--r-- 1 root root    4704 Sep 17  2017 _methods.py
-rw-r--r-- 1 root root 1582528 Dec  5  2017 multiarray.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 root root   48624 Dec  5  2017 multiarray_tests.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 root root   91642 Sep 29  2017 numeric.py
-rw-r--r-- 1 root root   28786 Sep 29  2017 numerictypes.py
-rw-r--r-- 1 root root   10384 Dec  5  2017 operand_flag_tests.cpython-36m-x86_64-linux-gnu.so
drwxr-xr-x 2 root root    4096 Mar 24 13:20 __pycache__
-rw-r--r-- 1 root root   29418 Sep 29  2017 records.py
-rw-r--r-- 1 root root   15345 Dec  5  2017 setup_common.py
-rw-r--r-- 1 root root   40704 Sep 29  2017 setup.py
-rw-r--r-- 1 root root   19081 Sep 29  2017 shape_base.py
-rw-r--r-- 1 root root   10408 Dec  5  2017 struct_ufunc_test.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 root root   44312 Dec  5  2017 test_rational.cpython-36m-x86_64-linux-gnu.so
drwxr-xr-x 4 root root    4096 Mar 24 13:20 tests
-rw-r--r-- 1 root root 1415520 Dec  5  2017 umath.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 root root   18856 Dec  5  2017 umath_tests.cpython-36m-x86_64-linux-gnu.so

Results of locate multiarray.py

/usr/lib/python2.7/dist-packages/numpy/core/tests/test_multiarray.py
/usr/lib/python2.7/dist-packages/numpy/core/tests/test_multiarray.pyc
/usr/lib/python2.7/dist-packages/numpy/matrixlib/tests/test_multiarray.py
/usr/lib/python2.7/dist-packages/numpy/matrixlib/tests/test_multiarray.pyc
/usr/lib/python3/dist-packages/numpy/core/tests/test_multiarray.py
/usr/lib/python3/dist-packages/numpy/matrixlib/tests/test_multiarray.py
10
  • 1
    Please share full error (backtrace). Commented Mar 24, 2020 at 18:58
  • 1
    Edited the question to reflect the full error message. Commented Mar 24, 2020 at 19:00
  • You will want to python -m pip install numpy, rather than apt installing it. apt-get might install it to either the system python3 or some other python3 Commented Mar 24, 2020 at 19:02
  • What about ls /usr/lib/python3/dist-packages/numpy/core/ and locate multiarray.py? Commented Mar 24, 2020 at 19:03
  • 2
    It will easier for you if you install a Python Virtual Environment like Anaconda. With this, you will be able to handle multiple versions of python. Commented Mar 24, 2020 at 19:05

1 Answer 1

0

The problem is that the deb numpy-python3 only works with python3.6. The (appallingly uninformative) error message is cause by a trial import in the __init__.py

try:
    from . import multiarray
except ImportError as exc:
    msg = """
Importing the multiarray numpy extension module failed.  Most
 :

That import fails because you are running python3.7, which attempts to load the dynamic library multiarray.cpython-37m-x86_64-linux-gnu.so, but numpy-python3 only provides multiarray.cpython-36m-x86_64-linux-gnu.so: this is the minor-version incompatibility that you observe.

If you look on the package description for numpy-python3, this is actually explicit

$ apt-cache show python3-numpy | grep Dep
Depends: python3 (<< 3.7), python3 (>= 3.6~), ...

and python3 provides a compatible version

$ apt-cache show python3 | grep Vers
Version: 3.6.7-1~18.04

So I'm afraid you're out of luck using the system Numpy with 3.7 or 3.8, you'll need to pip-install it (that should install it into the site-packages in /usr/local, not tested), but don't forget to do this as python3.7 -m pip ... since the system pip3 uses python3 which is python3.6 unless you've futzed around with update-alternatives.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.