ImportError: No module named numpy on Ubuntu after Numpy Installation

*爱你&永不变心* 提交于 2020-02-05 01:58:46

问题


I am trying to use numpy on Ubuntu 16.04. I have python 2.7.12 installed. I have tried:

sudo apt install python-numpy

sudo apt autoremove 

dpkg -L python-numpy

Here is an excerpt of the output:

/.
/usr
/usr/lib
/usr/lib/python2.7
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/numpy-1.11.0.egg-info
/usr/lib/python2.7/dist-packages/numpy-1.11.0.egg-info/dependency_links.txt
/usr/lib/python2.7/dist-packages/numpy-1.11.0.egg-info/PKG-INFO
/usr/lib/python2.7/dist-packages/numpy-1.11.0.egg-info/top_level.txt
/usr/lib/python2.7/dist-packages/numpy
/usr/lib/python2.7/dist-packages/numpy/lib
/usr/lib/python2.7/dist-packages/numpy/lib/shape_base.py

However, when I try to run a simple file such as this, I still get the same error.

#!/usr/bin/env python2

import numpy as np

a = np.array([1, 2, 3])

python test2.py 
Traceback (most recent call last):
  File "test2.py", line 3, in <module>
    import numpy as np
ImportError: No module named numpy

Is there anything left that I need to check for? Thanks!


回答1:


try from the command line,

pip install numpy --user

then you should be able to import numpy in a new python session.

but to really handle this sorta thing well, you should create sandboxed environments for projects where you specify not the packages and even the python version used. that way you don't accidentally install a package in the wrong path, or have it installed for python2 but not have it available if your default python is python3, that sorta thing.

if you download anaconda, you get a great way to manage all that: https://conda.io/docs/using/envs.html

otherwise you can use venv (stands for 'virtual environment'): https://docs.python.org/3/library/venv.html

UPDATE: and now pipenv, from the maker of Requests (Kenneth Reitz)



来源:https://stackoverflow.com/questions/45366594/importerror-no-module-named-numpy-on-ubuntu-after-numpy-installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!