我管理着一群用户,所以我想知道如何才能安装
numpy
供他们所有人使用,而不需要每个人自己安装软件包。
我有Python 2.7.17和Python 3.6.9(通过Ubuntu 18.04默认安装)。此外,我还安装了Python 3.7.5、Python 3.8.0和
numpy
,使用的方法如下。
sudo apt install python3.7
sudo apt install python3.8
sudo apt install python3-numpy
如果我运行python
或python3
或python3.6
(调用python 2.7.17或python 3.6.9),我可以很好地运行以下命令。
import numpy
然而,如果我在运行python3.7
或python3.8
后尝试运行上述程序我得到以下错误信息。
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)
当我安装numpy
时,它被安装到/usr/lib/python3/dist-packages
,这应该是好的,因为它在所有Python版本的sys.path()
上。
会不会因为使用apt拉出的numpy
的版本只适用于Python 3.6.9而无法工作?如果是这样的话,我应该如何为所有用户安装所有版本的 Python 的 numpy
?
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