Unable to import numpy - python

I'm on OS X Mavericks and new to Python. I have the Apple python environment and installed the official one from python.org.
When I try to import numpy from the python interpreter I get that the module can't be found.
import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>>
When I run:
$ pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
When I run the following commands on the terminal I get the following:
$which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
what to do because I'm going crazy!!!

I had a similar problem with numpy and other libraries common to scientific packages like matplotlib. You might try installing a Python distribution package like Anaconda, which includes several other useful libraries similar to numpy. Install link here: https://store.continuum.io/cshop/anaconda/. Best of luck.

I suggest not deleting the 'numpy' in python2.7 because it is a built-in module of python2.7 by macOS.
Try:python3 -m pip install numpy

Related

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.

I use Mac. my import numpy was working fine until I tried to install opencv on to my system

while installing opencv in did that ln -s command and now numpy module is not working if i try to install numpy it shows this
$ pip install numpy
Requirement already satisfied: numpy in /Users/deepakpatel/miniconda3/lib/python3.6/site-packages (1.15.0)
but when i try to import that module in python programs its not working it shows this
import numpy
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'numpy'
so i need some help with this guys
if you need more info just comment down below

How to import Scipy and Numpy in Python?

I am very new to Python and want to add Numpy and Scipy module. I think my question is very simple for you. I am using Python 3.06a.1 version. I think I already installed something called Anaconda that contains those library. When I type import scipy I get the following message:
import scipy
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import scipy
ImportError: No module named 'scipy'
also when I want to installed with command line I get the following message which means that I have it already.
localhost:~ user$ pip install scipy
Requirement already satisfied (use --upgrade to upgrade): scipy in ./anaconda/lib/python3.5/site-packages
localhost:~ user$
Please help me to fix this problem
You shouldn't have problem with scipy and numpy if you installed Anaconda. What I'm advising you may sound stupid, but I'm sure it has a good chance to solve your problem.
Relaunch Anaconda, reboot your computer, reinstall Anaconda.
Edit : also watch out to use "scipy" and not "spicy" as I just witnessed in your logs.
if you are using anaconda, try installing scipy using anaconda:
conda install scipy

why python failed to use or upgrade package installed by pip?

This problem may seem simple to most of you but I'm really confused. I tried to install numpy & pandas using pip. So initially I just did:
sudo pip install pandas.
It installed successfully but when i tried:import pandas there's error as:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas/src/numpy.pxd", line 157, in init pandas.hashtable (pandas/hashtable.c:22984)
ValueError: numpy.dtype has the wrong size, try recompiling
Then I assume it's the numpy version wrong (even pandas said installed a newer numpy) I tried to upgrade the numpy using "pip" but system reminded me don't have to.
As I checked, all my "pip" installed python packages are in /usr/local/lib/python2.7/site-package, in which the numpy version is 1.9.1 and pandas 0.15.1
When I do which python, it shows me the python path/usr/local/bin so I assume it's using the system patron and did installed all the packages accordingly
But when I typed in "python" in console, and tried:
import numpy as np
np.version.version
It showed 1.6.1 instead of 1.9.1
Seems it never gets upgraded or failed to use the numpy installed.
How should I fix this?
Thanks
Uninstall Numpy and then Re-install the newest version of it.
pip uninstall numpy
pip install numpy
I too was facing this problem earlier.

Scipy, Numpy, Matplotlib Troubles on OSX

I just installed scipy and numpy using homebrew and pip. I did the following:
brew install python
brew install gfortran
easy_install pip
sudo pip install numpy
sudo pip install scipy
numpy and scipy are both easily found in /Library/Python/2.7/site-packages, but when I open a python shell in the terminal and type:
import numpy
import scipy
I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
and the same for scipy. What's wrong? Pip seems to think they're installed.
The python shell you are running from the terminal is probably OSX pre-bundled python and not the one you installed (with numpy & scipy).
You can list the current paths using:
import sys
print(sys.path)
It might be a bit overkill, but I once wrote a short guide to install Python 2.7.x in OS X. You can find it here.
The bottom line is that right now you might have two versions of Python installed, and it can be a bit tricky to uninstall only one of them. If you're sure which one is using the right site-packages folder, then delete the other and update your path variables. If not, I'd suggest to follow that guide.

Categories