12

Actually I am shifting from Windows to Linux. Using pycharm on Windows I have a python 3 script that requires numpy and matplotlib to run, so I installed them on my Linux system using

sudo apt-get install python3-numpy
sudo apt-get install matplotlib3-numpy

But still when I try to run the script I get error:

from python3-numpy import  *
                ^
SyntaxError: invalid syntax

or:

from numpy import  *
ImportError: No module named 'numpy'
Kevin Bowen
  • 19,395
  • 55
  • 76
  • 81
rjbir
  • 123
  • 1
  • 1
  • 4

4 Answers4

14

You need to install numpy using pip
install pip :

sudo apt-get install python-pip python3-pip

Then install numpy using pip

sudo pip3 install -U numpy
mchid
  • 42,315
  • 7
  • 94
  • 147
Nadimul De Cj
  • 264
  • 2
  • 6
  • from Ubuntu 20.04+ avoid installing `python-pip` as python3 is default with no python 2.x – Scott Stensland Aug 14 '20 at 21:19
  • This doesn't answer why? Shouldn't I be able to access system-installed packages assuming I'm not running in a virtual env or some other type of isolation tool? – Raman Nov 02 '20 at 22:08
3

Are you sure that you run python3 and not just python, which defaults to python2.7 on most systems.

You can get the Version of python with

python --version

or

python3 --version
Jim Knopf
  • 51
  • 2
0

same issue I faced. I installed and uninstalled numpy from terminal but didn't work for pycharm. I found that my issue was with the environment I created in Pycharm. Most likely package isn't installed.

just install it on your current env follow below steps. I'm using Mac and should be the same on other OS:

  1. go to preference
  2. under project, click on project interpreter
  3. then you'll see all packages you installed. if you don't see numpy, just click on the plus sign and search then install. it should work now

Good luck

0

If the other answer didn't work for you, try:

sudo apt-get update; sudo apt-get install python-pip python3-pip
sudo pip install numpy; sudo pip3 install numpy

If that doesn't work, then you have other issues.

mchid
  • 42,315
  • 7
  • 94
  • 147
cat
  • 1,632
  • 1
  • 24
  • 47