ImportError: No module named matplotlib.pyplot Python [duplicate] - python

I am currently practicing matplotlib. This is the first example I practice.
#!/usr/bin/python
import matplotlib.pyplot as plt
radius = [1.0, 2.0, 3.0, 4.0]
area = [3.14159, 12.56636, 28.27431, 50.26544]
plt.plot(radius, area)
plt.show()
When I run this script with python ./plot_test.py, it shows plot correctly. However, I run it by itself, ./plot_test.py, it throws the followings:
Traceback (most recent call last):
File "./plot_test.py", line 3, in <module>
import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot
Does python look for matplotlib in different locations?
The environment is:
Mac OS X 10.8.4 64bit
built-in python 2.7
numpy, scipy, matplotlib is installed with:
sudo port install py27-numpy py27-scipy py27-matplotlib \
py27-ipython +notebook py27-pandas py27-sympy py27-nose

pip will make your life easy!
Step 1: Install pip - Check if you have pip already simply by writing pip in the python console. If you don't have pip, get a python script called get-pip.py , via here: https://pip.pypa.io/en/latest/installing.html or directly here: https://bootstrap.pypa.io/get-pip.py (You may have to use Save As ..)
Step 2: Take note of where the file got saved and cd the directory from command prompt. Run the get-pip.py script to install pip.
You can write in cmd this line within quotes: "python .\get-pip.py"
Step 3: Now in cmd type: pip install matplotlib
And you should be through.

You have two pythons installed on your machine, one is the standard python that comes with Mac OSX and the second is the one you installed with ports (this is the one that has matplotlib installed in its library, the one that comes with macosx does not).
/usr/bin/python
Is the standard mac python and since it doesn't have matplotlib you should always start your script with the one installed with ports.
If python your_script.py works then change the #! to:
#!/usr/bin/env python
Or put the full path to the python interpreter that has the matplotlib installed in its library.

If you are using Python 2, just run
sudo apt-get install python-matplotlib
The best way to get matplotlib is :
pip install matplotlib
cause the previous way may give you a old version of matplotlib

This worked for me, inspired by Sheetal Kaul
pip uninstall matplotlib
python3 -m pip install matplotlib
I knew it installed in the wrong place when this worked:
python2.7
import matplotlib

use pip3 install matplotlib to install matlplot lib.
By default, pip will install those package for 2.7 as it the native one.
using pip3 makes it specific for python 3, and make sure you have only one version of python 3

First check the version of Python
For python2:
sudo apt-get install python-matplotlib
For python3:
sudo apt-get install python3-matplotlib
If you mismatch the Matplotlib installation and the Python version you will get the no-module-error because no module for that version exits.

If you using Anaconda3
Just put
conda install -c conda-forge matplotlib

You can install the matplotlib package in python 3 by doing this
python3 -m pip install matplotlib --user
It's working for me.

If you have pip installed and Python configured to the path variables, Just run this command in the terminal.
pip install matplotlib

So I used python3 -m pip install matplotlib then import matplotlib.pyplot as plt and it worked.

I had a similar problem, using pip3 and all these things worked for installing matplotlib but not pyplot. This solved it for me:
import matplotlib as plt
from matplotlib import pyplot as pllt

I had a similar issue that I resolved and here is my issue:
I set everything up on python3 but I was using python to call my file for example:
I was typing "python mnist.py" ...since I have everything on python3 it was thinking I was trying to use python 2.7
The correction:
"python3 mnist.py" - the 3 made all the difference
I'm by no means an expert in python or pip, but there is definitely a difference between pip and pip3 (pip is tied to python 2.7) (pip3 is tied to python 3.6)
so when installing for 2.7 do: pip install
when installing for 3.6 do: pip3 install
and when running your code for 2.7 do: python
when running your code for 3.6 do: python3
I hope this helps someone!

I bashed my head on this for hours until I thought about checking my .bash_profile. I didn't have a path listed for python3 so I added the following code:
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
And then re-installed matplotlib with sudo pip3 install matplotlib. All is working beautifully now.

The file permissions on my virtual environment directory and my project directory were not correct and, thus, would not allow me to install the proper packages. I upadated them by running:
sudo chown user:user -R [project folder]
sudo chown user:user -R [environment folder]
In the above your should use your own usernames in place of "user". The -R recurses through all subfolders and files.

Working on the django project and faced same problem,
This is what I did.
Check if you have matplotlib already simply by writing pip show matplotlib in the python terminal.
If dont, run the command pip install matplotlib.(make sure you have pip downloaded)
Run the command pip show matplotlib again.
If the library is successfully downloaded, you can run your project (py manage.py runserver)

If you are in a venv, don't install these libs within the venv.
Installing them from outside helped me.

For me, with PyCharm and Python 3.8 on WIN10 environment, the solution was inside the IDE of PyCharm itself.
From the IDE and Project Setting (the gear on the top right corner), I've chosen Settings -->Project:Python-->Python Interpreter and you can see all the packages installed (and matplotlib wasn't present in the Package list).
Click on the + icon in the upper left corner for Package installation, and next will be opening a new window with the available packages for PyCharm. In the find box was sufficient to type matplotlib, select it and click on Install Package.
Here a screen-shot of PyCharm environment (as requested on 21/08/2021) :

If you experienced this error ModuleNotFoundError: No module named 'matplotlib' while using venv and running pytest like me, you can check by comparing the path type pytest shows and the path type python shows. In my case pytest wasn't under venv/bin directory like python, I installed pytest by pip and reactivated venv. See https://stackoverflow.com/a/54597424/3622415

I have installed matplotlib using both pip and conda but experienced this error ModuleNotFoundError: No module named 'matplotlib' .
I fix by following.
Because It might have an old version of Jupyter notebook, so i try this command to install it in the current kernel.
import sys
!{sys.executable} -m pip install seaborn
In the New Jupyter version (2019) can be installed simply as:
%pip install matplotlib

I solved by conda. Once installed miniconda or anaconda, type
conda install matplotlib
then, when prompted, type
y

in sublime text you can set
"cmd": ["python3", "-u", "$file"]
in tools > buildsystem > new build system
it worked for me

Related

No module name 'tensorflow'

The requirements for the code to run is
Python 2.7
TensorFlow 1.n
SciPy & NumPy
I have python 2.7.8 by checking python --version. Installing them on python website also lead to a message saying there is no software to install so I assumed that I already have python 2.7x
For tensorflow I have install it using pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py3-none-any.whl
and for Scipy and numpy i did brew install numpy scipy ipython jupyter
I have a python env setup call mypython.
Using pip list I have the following modules install as shown in the image.
But still VScode prompt an error and say that No module named 'tensorflow'when i run the code file.
How do I solve this?
enter image description here
Install Python extension instead of MagicPython;
You're using mypython in integrated Terminal but in left bottom corner, you select the global one,which is python3.10.1 as interpreter. Open Command Palette and choose Python: Select Interpreter, select mypython then reload window,the error should go away
Think you might be using the wrong pip. Could you run following in your terminal, with your venv activated.
$ pip --version
$ pip3 --version
Try installing with pip instead of pip3

No module named 'numpy' [duplicate]

I have a very similar question to this question, but I am still one step behind. I have only one version of Python 3 installed on my Windows 7 (sorry) 64-bit system.
I installed NumPy following this link - as suggested in the question. The installation went fine but when I execute
import numpy
I got the following error:
Import error: No module named numpy
You can simply use
pip install numpy
Or for python3, use
pip3 install numpy
Support for Python 3 was added in NumPy version 1.5.0, so to begin with, you must download/install a newer version of NumPy.
Or simply using pip:
python3 -m pip install numpy
Installing Numpy on Windows
Open Windows command prompt with administrator privileges (quick method: Press the Windows key. Type "cmd". Right-click on the
suggested "Command Prompt" and select "Run as Administrator)
Navigate to the Python installation directory's Scripts folder using the "cd" (change directory) command. e.g. "cd C:\Program Files (x86)\PythonXX\Scripts"
This might be: C:\Users\\AppData\Local\Programs\Python\PythonXX\Scripts or C:\Program Files (x86)\PythonXX\Scripts (where XX represents the Python version number), depending on where it was installed. It may be easier to find the folder using Windows explorer, and then paste or type the address from the Explorer address bar into the command prompt.
Enter the following command: "pip install numpy".
You should see something similar to the following text appear as the package is downloaded and installed.
Collecting numpy
Downloading numpy-1.13.3-2-cp27-none-win32.whl (6.7MB)
100% |################################| 6.7MB 112kB/s
Installing collected packages: numpy
Successfully installed numpy-1.13.3
I think there are something wrong with the installation of numpy.
Here are my steps to solve this problem.
go to this website to download correct package: http://sourceforge.net/projects/numpy/files/
unzip the package
go to the document
use this command to install numpy: python setup.py install
I also had this problem (Import Error: No module named numpy) but in my case it was a problem with my PATH variables in Mac OS X. I had made an earlier edit to my .bash_profile file that caused the paths for my Anaconda installation (and others) to not be added properly.
Just adding this comment to the list here in case other people like me come to this page with the same error message and have the same problem as I had.
You can try:
py -3 -m pip install anyPackageName
In your case use:
py -3 -m pip install numpy
You should try to install numpy using one of those:
pip install numpy
pip2 install numpy
pip3 install numpy
For some reason in my case pip2 solved the problem
Faced with same issue
ImportError: No module named numpy
So, in our case (we are use PIP and python 2.7) the solution was SPLIT pip install commands :
From
RUN pip install numpy scipy pandas sklearn
TO
RUN pip install numpy scipy
RUN pip install pandas sklearn
Solution found here : https://github.com/pandas-dev/pandas/issues/25193, it's related latest update of pandas to v0.24.0
You installed the Numpy Version for Python 2.6 - so you can only use it with Python 2.6. You have to install Numpy for Python 3.x, e.g. that one: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/numpy-1.6.1-win32-superpack-python3.2.exe/download
For an overview of the different versions, see here: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/
I had this problem too after I installed Numpy. I solved it by just closing the Python interpreter and reopening. It may be something else to try if anyone else has this problem, perhaps it will save a few minutes!
I had numpy installed on the same environment both by pip and by conda, and simply removing and reinstalling either was not enough.
I had to reinstall both.
I don't know why it suddenly happened, but the solution was
pip uninstall numpy
conda uninstall numpy
uninstalling from conda also removed torch and torchvision.
then
conda install pytorch-cpu torchvision-cpu -c pytorch
and
pip install numpy
this resolved the issue for me.
For those using python 2.7, should try:
apt-get install -y python-numpy
Instead of pip install numpy
I too faced the above problem with phyton 3 while setting up python for machine learning.
I followed the below steps :-
Install python-2.7.13.msi
• set PATH=C:\Python27
• set PATH=C:\Python27\Scripts
Go to http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy
Downloaded:- -- numpy-1.13.1+mkl-cp27-cp27m-win32.whl
--scipy-0.18.0-cp27-cp27m-win32.whl
Installing numpy:
pip install numpy-1.13.1+mkl-cp27-cp27m-win32.whl
Installing scipy:
pip install scipy-0.18.0-cp27-cp27m-win32.whl
You can test the correctness using below cmds:-
>>> import numpy
>>> import scipy
>>> import sklearn
>>> numpy.version.version
'1.13.1'
>>> scipy.version.version
'0.19.1'
>>>
I'm not sure exactly why I was getting the error, but pip3 uninstall numpy then pip3 install numpy resolved the issue for me.
Those who are using xonsh, do xpip install numpy.
For installing NumPy via Anaconda(use below commands):
conda install -c conda-forge numpy
conda install -c conda-forge/label/broken numpy
import numpy as np
ImportError: No module named numpy
I got this even though I knew numpy was installed and unsuccessfully tried all the advice above. The fix for me was to remove the as np and directly refer to modules . (python 3.4.8 on Centos)
.
import numpy
DataTwo=numpy.stack((OutputListUnixTwo))...
For me, on windows 10, I had unknowingly installed multiple python versions (One from PyCharm IDE and another from Windows store). I uninstalled the one from windows Store and just to be thorough, uninstalled numpy pip uninstall numpy and then installed it again pip install numpy. It worked in the terminal in PyCharm and also in command prompt.
this is the problem of the numpy's version, please check out $CAFFE_ROOT/python/requirement.txt. Then exec: sudo apt-get install python-numpy>=x.x.x, this problem will be sloved.
I did everything from the answers here but nothing worked. So I deleted all the previous installations of numpy using the commands below.
sudo rm -rf /usr/lib/python3/dist-packages/numpy*
sudo rm -rf /usr/lib/python3.7/dist-packages/numpy*
sudo rm -rf /usr/lib/python2.7/dist-packages/numpy*
Then just install using pip3.
sudo pip3 install numpy
Run
conda update --all
PS recall calling python using either "python2" or "python3" (not merely "python").
solution for me - I installed numpy inside a virtual environment, but then running ipython was not inside virtual env:
(venv) ➜ which python
/Users/alon/code/google_photos_project/venv/bin/python
(venv) ➜ which ipython
/usr/bin/ipython
so I had to install ipython, and run ipython from the venv like this:
python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'
I was trying to use NumPy in Intellij but was facing the same issue so, I figured out that NumPy also comes with pandas. So, I installed pandas with IntelliJ tip and later on was able to import NumPy. Might help someone someday!
As stated in other answers, this error may refer to using the wrong python version. In my case, my environment is Windows 10 + Cygwin. In my Windows environment variables, the PATH points to C:\Python38 which is correct, but when I run my command like this:
./my_script.py
I got the ImportError: No module named numpy because the version used in this case is Cygwin's own Python version even if PATH environment variable is correct.
All I needed was to run the script like this:
py my_script.py
And this way the problem was solved.
Try uninstalling and then reinstalling the Python extension for VSCode.
I tried many different solutions, but this "hard refresh" was the only one that worked for me.
I just had the same problem as well! It turns out the problem happens when you're installing Numpy to a version of python and trying to run the program using another python version. Probably the global version of Python your text editor opens by default is different from the one that you need for the version of numpy you are running.
So to start off, run:
which python
python --version
which pip
pip list
If you can find numpy on the list, its most likely the python version you are using is not compatible with the version of numpy installed. Try switching to a different version of Python in this case.
If numpy is not installed just pip install numpy or pip3 install numpy depending upon your version of python.
For whom installation target is Raspberry Pi, as here they suggest:
sudo apt-get install libatlas-base-dev
could be working.
On MacOs, if you are getting this error in Pycharm and you installed Python3 and NumPy through Homebrew, the python interpreter path is probably not pointing to the Python interpreter that is installed by Homebrew. In Pycharm, go to Preferences>Project: [Project Name]>Python Interpreter, and enter /opt/homebrew/bin/python3 for the path to python interpreter.

No module named 'plotly'

I am new to python and I'm following a tutorial using python3. I installed plotly and I can see it in the pip list and pip3 list and python help("modules"). However, when I tried to import the module (from plotly import offline) I got the error:
ModuleNotFoundError: No module named 'plotly'.
Tried to reinstall but it did not work.
I can import other modules in the list, like pygame or matplotlib without a problem.
It is usually a good idea to create a virtual environment to install additional modules. This will create a sealed Python environment with only the packages you specify. This usually fixes such errors, as Python sometimes installs packages where they can later not be found anymore. It is also a good idea to not use pip, as it might point to a pip from a different python version. Also it makes sense to upgrade pip before installing packages.
Try the following:
python3 -m venv env
. env/bin/activate (on Linux)
.\env\Scripts\activate (on Windows)
Check which packages we have:
python -m freeze
Here make sure this does not show anything except pkg-resources==0.0.0. Otherwise your PYTHONPATH might be mesed up.
Upgrade pip and install your package:
python -m pip install --upgrade pip
python -m pip install plotly
Run python and import your package:
python
>>> import plotly
If I typ this:
pip install plotly
in a CMD and this:
>>> from plotly import offline
In the interpreter it workes fine,
try uninstalling and reinstalling plotly:
pip uninstall plotly
Enter
y when it says Proceed (y/n)?
And install again with
pip install plotly
I had the same problem; after uninstalling/installing plotly, use venv, I realised (after 2h) that my script name was "plotly.py" => that was the cause of the error

Problems with installing matplotlib in python 3.6

I'm trying to teach myself python, and I feel out of my depth. To start, I am working on a mac which already comes with python 2.7 installed.
I installed python 3.6 recently and have been using it to teach myself the basics. I'd like to eventually learn how to produce mathematical plots in python, and I know I will need the matplotlib package to do that.
Following some advice online, I was told that python3 already comes with pip installed, which is what I thought I should use to install matplotlib. The advice said I should type the following into the mac terminal:
python3.6 -m pip install matplotlib
I typed this, and it seemed like the package was installing, but I ended up getting some sort of error code that said:
Command "python setup.py egg_info" failed with error code 1 in [folder].
I tried opening IDLE and typing "import matplotlib", but I got the error: "no module named matplotlib". I also tried typing "import matplotlib.pyplot as plt", but I got the same error.
Based on further research and this youtube video, I've decided to just install miniconda in order to have access to the matplotlib package.
The problem is, I'm not sure if I should somehow be uninstalling whatever was installed when I ran the code above to install matplotlib. I've actually run that line of code 3 or 4 times. Should I remove anything before installing miniconda? Also, I am running python 3.6, while miniconda is listed on the website as being for python 3.5. Does this mean it won't work for my version of python?
Running pip like that would install packages system-wide. I'm guessing it's failing because you're not running as root (i.e. the administrator user). But wait! Don't try again as root! Instead of installing packages, do it in a virtual environment. First create it:
virtualenv myenv
This creates a directory called myenv with a bunch of stuff in it (so make note of where you run this command). Whenever you want to use the virtual environment (like straight away!) you first need to activate it:
. myenv/bin/activate
Don't miss out that dot (followed by a space) at the beginning! As the other answer says, the first thing you should do in it is upgrade pip:
pip install --upgrade pip
Now you're ready install whatever else you like:
pip install matplotlib
One last note: The virtual environment is tied to a particular Python version. By default it uses the system's Python 2.7 installation, so to use a different one you need to specify it when you create the virtual environment, like this (if that Python version is installed system-wide):
virtualenv -p python3.5 myenv
Or like this (if that Python version is not installed system-wide):
virtualenv -p /path/to/my/installation/of/python3.5 myenv
While the virtual environment is activated, you don't need to specify the particular path/version of Python. Just run it like this:
python
I also encountered many problems during my installation.
It seems that version 2 of matplotlib is not compatible with Python version 3.
Finally, I succeeded by specifying version 3 of matplotlib as follows with the following command:
sudo apt-get install python3-matplotlib
Reference from the Matplotlib website:
https://matplotlib.org/users/installing.html#building-on-linux
Try upgrade setup tools
--upgrade setuptools
or
easy_install -U setuptools
or upgrade pip
pip install --upgrade pip
I ended up downloading anaconda and using the python interpreter that comes with it, as anaconda comes with matplotlib and many other python packages of interest.
the pip command typically is for the Python 2. use pip3 instead to install the libraries in the python 3.X path
This should work
pip3 install matplotlib
The solution that work for me in python 3.6 is the following
py -m pip install matplotlib
Matplotlib files are downloaded in ~/.local/lib/python3.6/site-packages/ and not in /usr/lib/python3.6/ .
Try the command:
sudo cp -r ~/.local/lib/python3.6/site-packages/* /usr/lib/python3.6/

Error "Import Error: No module named numpy" on Windows

I have a very similar question to this question, but I am still one step behind. I have only one version of Python 3 installed on my Windows 7 (sorry) 64-bit system.
I installed NumPy following this link - as suggested in the question. The installation went fine but when I execute
import numpy
I got the following error:
Import error: No module named numpy
You can simply use
pip install numpy
Or for python3, use
pip3 install numpy
Support for Python 3 was added in NumPy version 1.5.0, so to begin with, you must download/install a newer version of NumPy.
Or simply using pip:
python3 -m pip install numpy
Installing Numpy on Windows
Open Windows command prompt with administrator privileges (quick method: Press the Windows key. Type "cmd". Right-click on the
suggested "Command Prompt" and select "Run as Administrator)
Navigate to the Python installation directory's Scripts folder using the "cd" (change directory) command. e.g. "cd C:\Program Files (x86)\PythonXX\Scripts"
This might be: C:\Users\\AppData\Local\Programs\Python\PythonXX\Scripts or C:\Program Files (x86)\PythonXX\Scripts (where XX represents the Python version number), depending on where it was installed. It may be easier to find the folder using Windows explorer, and then paste or type the address from the Explorer address bar into the command prompt.
Enter the following command: "pip install numpy".
You should see something similar to the following text appear as the package is downloaded and installed.
Collecting numpy
Downloading numpy-1.13.3-2-cp27-none-win32.whl (6.7MB)
100% |################################| 6.7MB 112kB/s
Installing collected packages: numpy
Successfully installed numpy-1.13.3
I think there are something wrong with the installation of numpy.
Here are my steps to solve this problem.
go to this website to download correct package: http://sourceforge.net/projects/numpy/files/
unzip the package
go to the document
use this command to install numpy: python setup.py install
I also had this problem (Import Error: No module named numpy) but in my case it was a problem with my PATH variables in Mac OS X. I had made an earlier edit to my .bash_profile file that caused the paths for my Anaconda installation (and others) to not be added properly.
Just adding this comment to the list here in case other people like me come to this page with the same error message and have the same problem as I had.
You can try:
py -3 -m pip install anyPackageName
In your case use:
py -3 -m pip install numpy
You should try to install numpy using one of those:
pip install numpy
pip2 install numpy
pip3 install numpy
For some reason in my case pip2 solved the problem
Faced with same issue
ImportError: No module named numpy
So, in our case (we are use PIP and python 2.7) the solution was SPLIT pip install commands :
From
RUN pip install numpy scipy pandas sklearn
TO
RUN pip install numpy scipy
RUN pip install pandas sklearn
Solution found here : https://github.com/pandas-dev/pandas/issues/25193, it's related latest update of pandas to v0.24.0
You installed the Numpy Version for Python 2.6 - so you can only use it with Python 2.6. You have to install Numpy for Python 3.x, e.g. that one: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/numpy-1.6.1-win32-superpack-python3.2.exe/download
For an overview of the different versions, see here: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/
I had this problem too after I installed Numpy. I solved it by just closing the Python interpreter and reopening. It may be something else to try if anyone else has this problem, perhaps it will save a few minutes!
I had numpy installed on the same environment both by pip and by conda, and simply removing and reinstalling either was not enough.
I had to reinstall both.
I don't know why it suddenly happened, but the solution was
pip uninstall numpy
conda uninstall numpy
uninstalling from conda also removed torch and torchvision.
then
conda install pytorch-cpu torchvision-cpu -c pytorch
and
pip install numpy
this resolved the issue for me.
For those using python 2.7, should try:
apt-get install -y python-numpy
Instead of pip install numpy
I too faced the above problem with phyton 3 while setting up python for machine learning.
I followed the below steps :-
Install python-2.7.13.msi
• set PATH=C:\Python27
• set PATH=C:\Python27\Scripts
Go to http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy
Downloaded:- -- numpy-1.13.1+mkl-cp27-cp27m-win32.whl
--scipy-0.18.0-cp27-cp27m-win32.whl
Installing numpy:
pip install numpy-1.13.1+mkl-cp27-cp27m-win32.whl
Installing scipy:
pip install scipy-0.18.0-cp27-cp27m-win32.whl
You can test the correctness using below cmds:-
>>> import numpy
>>> import scipy
>>> import sklearn
>>> numpy.version.version
'1.13.1'
>>> scipy.version.version
'0.19.1'
>>>
I'm not sure exactly why I was getting the error, but pip3 uninstall numpy then pip3 install numpy resolved the issue for me.
Those who are using xonsh, do xpip install numpy.
For installing NumPy via Anaconda(use below commands):
conda install -c conda-forge numpy
conda install -c conda-forge/label/broken numpy
import numpy as np
ImportError: No module named numpy
I got this even though I knew numpy was installed and unsuccessfully tried all the advice above. The fix for me was to remove the as np and directly refer to modules . (python 3.4.8 on Centos)
.
import numpy
DataTwo=numpy.stack((OutputListUnixTwo))...
For me, on windows 10, I had unknowingly installed multiple python versions (One from PyCharm IDE and another from Windows store). I uninstalled the one from windows Store and just to be thorough, uninstalled numpy pip uninstall numpy and then installed it again pip install numpy. It worked in the terminal in PyCharm and also in command prompt.
this is the problem of the numpy's version, please check out $CAFFE_ROOT/python/requirement.txt. Then exec: sudo apt-get install python-numpy>=x.x.x, this problem will be sloved.
I did everything from the answers here but nothing worked. So I deleted all the previous installations of numpy using the commands below.
sudo rm -rf /usr/lib/python3/dist-packages/numpy*
sudo rm -rf /usr/lib/python3.7/dist-packages/numpy*
sudo rm -rf /usr/lib/python2.7/dist-packages/numpy*
Then just install using pip3.
sudo pip3 install numpy
Run
conda update --all
PS recall calling python using either "python2" or "python3" (not merely "python").
solution for me - I installed numpy inside a virtual environment, but then running ipython was not inside virtual env:
(venv) ➜ which python
/Users/alon/code/google_photos_project/venv/bin/python
(venv) ➜ which ipython
/usr/bin/ipython
so I had to install ipython, and run ipython from the venv like this:
python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'
I was trying to use NumPy in Intellij but was facing the same issue so, I figured out that NumPy also comes with pandas. So, I installed pandas with IntelliJ tip and later on was able to import NumPy. Might help someone someday!
As stated in other answers, this error may refer to using the wrong python version. In my case, my environment is Windows 10 + Cygwin. In my Windows environment variables, the PATH points to C:\Python38 which is correct, but when I run my command like this:
./my_script.py
I got the ImportError: No module named numpy because the version used in this case is Cygwin's own Python version even if PATH environment variable is correct.
All I needed was to run the script like this:
py my_script.py
And this way the problem was solved.
Try uninstalling and then reinstalling the Python extension for VSCode.
I tried many different solutions, but this "hard refresh" was the only one that worked for me.
I just had the same problem as well! It turns out the problem happens when you're installing Numpy to a version of python and trying to run the program using another python version. Probably the global version of Python your text editor opens by default is different from the one that you need for the version of numpy you are running.
So to start off, run:
which python
python --version
which pip
pip list
If you can find numpy on the list, its most likely the python version you are using is not compatible with the version of numpy installed. Try switching to a different version of Python in this case.
If numpy is not installed just pip install numpy or pip3 install numpy depending upon your version of python.
For whom installation target is Raspberry Pi, as here they suggest:
sudo apt-get install libatlas-base-dev
could be working.
On MacOs, if you are getting this error in Pycharm and you installed Python3 and NumPy through Homebrew, the python interpreter path is probably not pointing to the Python interpreter that is installed by Homebrew. In Pycharm, go to Preferences>Project: [Project Name]>Python Interpreter, and enter /opt/homebrew/bin/python3 for the path to python interpreter.

Categories