2

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 sudo apt-get install python-numpy Commented Jul 28, 2017 at 6:51

2 Answers 2

3

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)

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

1 Comment

It worked! Thank you! I will accept your answer in a few minutes.
2

For Ubuntu

Try

sudo apt install python-numpy 

Then try the command

python -c "import numpy; print(numpy.__version__)" 

It will show you the installed numpy version

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.