No module named 'numpy' but Requirement already satisfied: numpy - python

When I want to execute my script I got the error: ModuleNotFoundError: No module named 'numpy'. But the module is already installed as said me the answer to the install command:
C:\WINDOWS\system32>pip install numpy
Requirement already satisfied: numpy in c:\users\simeo\anaconda3\envs\tensorflow1\lib\site-packages (1.17.2)
I'm quite new with Python, so I don't understand why it's not working and what could be the problem.
I'm using Windows 10 (64 bits). I installed Python 3.7
Thanks in advance!

For Windows try either two of these methods in cmd:
pip3 install numpy
pip3 install -U numpy
directly download latest version from sourceforge.net
If you are using pycharm, it can not install numpy from interpreter settings. After one of above method works, try installing numpy in pycharm again through interpreter settings.

You need to upgrade your Numpy library. Your current Keras version is not compatible with your Numpy module. You can use the below-given command to upgrade Numpy.pip install -U numpy

Try adding this to your code, above everything else:
import numpy

Related

Jupyter Notebook ModuleError after Homebrew Upgrade

I have been using Jupyter for some time now and it has worked just fine. I have Jupyter and Python installed via Homebrew. I am running on MacOS.
Yesterday, I ran the command brew upgrade and now my Jupyter notebook is unable to find any of the installed python packages. I will use Numpy as the example.
When inside of a Jupyter notebook, I try to do
import numpy
I get the message:
ModuleNotFoundError: No module named 'numpy'
If, however, I launch python in a terminal window, then I can import Numpy without issue.
I first checked that the package was installed correctly by re-issuing the install command
brew install numpy
which outputs:
Warning: numpy 1.18.4 is already installed and up-to-date
To reinstall 1.18.4, run `brew reinstall numpy`
I also ran
pip install numpy
and got:
Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.18.4)
Now, this is where I got confused because I expected the path to point to something like /usr/local/Cellar/, so I checked the path inside of the Jupyter notebook:
import sys
sys.path
which outputs:
['/Users/kseuro/Dropbox/Dev/',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python38.zip',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/lib-dynload',
'/usr/local/opt/python#3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages/IPython/extensions',
'/Users/kseuro/.ipython']
Ok, so Homebrew wants Jupyter to use Python3.8? So I tried brew switch python 3.8 and got:
Error: python does not have a version "3.8" in the Cellar.
python's installed versions: 3.7.7
I feel like I'm out of my depth now and need help figuring out what to do next. I don't want to start by just changing paths around.
Suggestions? Thanks so much.
I figured out what to do — posting the solution for my future self and others who may stumble upon this.
Since Jupyerlab is in its own Cellar, the Python packages need to end up in the
/usr/local/Cellar/jupyterlab/x.y.z/libexec/lib/python3.x/site-packages
directory, where x, y, z are integers, so that the Jupyter kernel can find them.
You can do this by calling:
import sys
!{sys.executable} -m pip install 'package-name'
inside of the Jupyer notebook.
All is well, again.

tensorflow python 3.7.2 import error with anaconda [duplicate]

I have installed Ancaconda3 and Tensorflow. When I try to import Tensorflow in python shell I receive the following error:
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
ImportError: numpy.core.multiarray failed to import
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "", line 980, in _find_and_load SystemError:
<class '_frozen_importlib._ModuleLockManager'> returned a result with
an error set ImportError: numpy.core._multiarray_umath failed to
import ImportError: numpy.core.umath failed to import
I am not sure what the problem is as numpy is installed on my system and can be successfully imported in python.
I am using Windows10.
I also had the same issue.
It got resloved once I upgraded the numpy from 1.15.4 to 1.16.1.
If you're using pip:
pip install numpy --upgrade
Numpy that came with Anaconda3 is of version 1.15.4. so i upgraded and it worked.
Side note: if you're also using scikit-image in your script, be aware that numpy 1.16.3 has a conflict with old versions of scikit-image (e.g. you may get ImportError: cannot import name '_validate_lengths'). In that case, pip install --upgrade scikit-image from terminal solved the issue for me.
Kindly check whether you have installed the numpy package from pip. Because if you are running on conda evironment, then all packages need to be downloaded from there.
Please use the below mentioned statement for this purpose
conda install -c anaconda numpy
Also make sure that the numpy version supports the Python version you are using.
You can use two options in python 3.6
Install
py pip -m install numpy==1.14.5
Upgrade
py pip install numpy --upgrade
Note: the version most recently is 1.14.5
I also had this issue with python 3.8.9 and Numpy 1.24.1.
Downgrading to Numpy 1.21.0 fixed the issue.

ModuleNotFoundError: No module named 'spatial'

I've been faced to Module Not Found Error in a script which all it's requirements has been installed. I'm trying to import spatial library:
import spatial
This library is located here:
C:\Users\ASUS\AppData\Local\Programs\Python\Python37\Lib\site-packages\scipy\spatial
I checked installed packages through pip list and it was okay. I tried to install spatial-lib in Pycharm project environment but it couldn't be done:
Could not find a version that satisfies the requirement spatial-lib (from versions: )
No matching distribution found for spatial-lib
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
It's nonesence, because my pip is up-to-date. Maybe good to say, importing scipy has such probelms too.
It looks like spatial is a sub-package of scipy. Therefore, to import spatial, you should use the following:
from scipy import spatial

Can't import numpy in python 2.7

When running the following code in python 2.7:
import numpy
I get the result:
ImportError: No module named numpy
I have however got numpy installed for python 2.7, which is seen when running the following in terminal:
pip install numpy
I get the following:
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Working on macOS10.13.1
What am I missing?
Any help will be greatly appreciated!
have you tried uninstalling the numpy package and re-installing it? As mentioned you may be running python 3 instead of python 2 which could cause this issue.alternatively you could install an api like anaconda which comes with numpy pre-installed this may resolve the missing module. anaconda website: https://www.anaconda.com/download/

How to find and uninstall the numpy duplicate versions

I am trying to install the library GPy. Although the installation is successful, I have a question on my numpy version.
GPy library can be found here https://github.com/SheffieldML/GPy
The current version of my numpy is 1.9.3
>>> import numpy
>>> numpy.version.version
'1.9.3'
But when I perform python setup.py install for GPy, it refers to numpy 1.10.0. I checked in python 2.7/site-packages there only one version of numpy exist that too 1.9.3
Using /home/vinod/anaconda/lib/python2.7/site-packages
Searching for scipy==0.16.0
Best match: scipy 0.16.0
Adding scipy 0.16.0 to easy-install.pth file
Using /home/vinod/anaconda/lib/python2.7/site-packages
Searching for numpy==1.10.0
Best match: numpy 1.10.0
Adding numpy 1.10.0 to easy-install.pth file
Using /home/vinod/anaconda/lib/python2.7/site-packages
Finished processing dependencies for GPy==0.8.8
vinod#vinod-Lenovo-G580:~/GPy$
Since it's referring to another version am getting error like
File"__init__.pxd", line 155, in init GPy.util.linalg_cython (GPy/util/linalg_cython.c:4238)
ValueError: numpy.dtype has the wrong size, try recompiling
Could anyone tell me how to find and remove the numpy 1.10.0 ?
From the conda FAQ:
conda update numpy --no-pin
I tried the following steps and it works but still I don't know how.
I opened the setup.py and changed the numpy condition from numpy >= 1.7 to numpy <=1.9.3
Then I performed the python setup.py install
Then I uninstalled GPy using pip uninstall GPy
Again I installed GPy but using pip install GPy. Note: in previous steps I used git and installed separately.
This time it upgraded my numpy to 1.10.0 during installation and got installed successfully
Finally now it works well.
python Packeges
installed
select the library you want to unistall
"delate" by selecting tenter image description herehe menu on the right

Categories