error importing numpy in python 3.5 - python

I tried installing numpy with homebrew, but instead it installed in the Python 2.7 version. I found this out by following the answer on this post: Can't import numpy
Which is very strange especially since I specifically asked for python3:
M$ brew install numpy --with-python3
Warning: homebrew/python/numpy-1.11.1 already installed
However, when I try importing it in Python 3.5 I always get the same error:
File "Dataframe.py", line 1, in <module>
import numpy as np
ImportError: No module named 'numpy'
How can I get it to work as intended? I am on mac os 10.11.3

Check that you have Python 3.5 installed by running which python3 and which python (to make sure your versions aren't mixed up).
Then, to install for Python 3, you should run pip3 install numpy. It's a good idea to use the given Python tools to install Python-related packages.

Related

No module named pandas but pandas is already installed in linux

I have two python distributions(python2.7,python3.6) and in both I have installed pandas and numpy as well but cant use
These are the errors caused when i tried to import pandas
in python 2.7
File "/usr/local/lib/python2.7/dist-packages/pandas/init.py", line 19, in
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
then imported numpy
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try git clean -xdf (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
in python 3.6
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'pandas'
Most of these cases, the problem is that you are installing pandas in another environment. The easy solution here is using Anaconda.
Anaconda is focused on environments. First, you should choose installation of python2 or python3. Then, you can install this version of Anaconda in Linux: https://www.anaconda.com/download/#linux
For example:
64-Bit (x86) Installer (622 MB) Python3:
$ wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
Then you need, install in your system:
$ bash Anaconda3-5.2.0-Linux-x86_64.sh
Be cautious in the interactive dialog in order to install Anaconda. Remember the route of the installation.
When you have Anaconda in a folder named: anaconda 3 (for example). go to route: .../anaconda3/bin.
Now, you should execute:
$ source activate
Now you are in base environment, you can install the packages that you need (pandas and numpy are install by default). However, I recommend you create a new environment for each new proyect (see https://conda.io/docs/_downloads/conda-cheatsheet.pdf).
Imagine that you have (base) environment. In this environment try:
$ python
The first message gives you the python version. Anyway you can try:
>>> import sys
>>> sys.version
In order to know the version that you are using.

Numpy not found after installation

I just installed numpy on my PC (running windows 10, running python 3.5.2) using WinPython, but when i try to import it in IDLE with: import numpy I get the ImportError: Traceback (most recent call last):
File "C:\Users\MY_USERNAME\Desktop\DATA\dataScience1.py", line 1, in <module>
import numpy
ImportError: No module named 'numpy'.
Did I possibly install it incorrectly, or do I need to do something else before it can be used?
In Linux and Mac OS systems we can install modules directly by mentioning
pip install modulename (or) sudo pip install modulename
in terminal or command prompt.
But in windows we should mention location of python folder in c directory like c:\python3 and later we should use
pip install modulename
in command prompt or terminal.
or
go n check whether numpy module is installed in sitepackages of python 3 folder in c directory or not.
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 use this command to install numpy. This will install the latest version of numpy.
pip install numpy
Winpython has two size, and the smallest "Zero" size doesn't include numpy

ImportError: cannot import name NUMPY_MKL

I am trying to run the following simple code
import scipy
scipy.test()
But I am getting the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 586, in runfile
execfile(filename, namespace)
File "C:/Users/Mustafa/Documents/My Python Code/SpectralGraphAnalysis/main.py", line 8, in <module>
import scipy
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 61, in <module>
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name NUMPY_MKL
I am using python 2.7 under windows 10.
I have installed scipy but that does not seem to solve the problem
Any help is appreciated.
If you look at the line which is causing the error, you'll see this:
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
This line comment states the dependency as numpy+mkl (numpy with Intel Math Kernel Library). This means that you've installed the numpy by pip, but the scipy was installed by precompiled archive, which expects numpy+mkl.
This problem can be easy solved by installation for numpy+mkl from whl file from here.
Reinstall numpy-1.11.0_XXX.whl (for your Python) from www.lfd.uci.edu/~gohlke/pythonlibs. This file has the same name and version if compare with the variant downloaded by me earlier 29.03.2016, but its size and content differ from old variant. After re-installation error disappeared.
Second option - return back to scipy 0.17.0 from 0.17.1
P.S. I use Windows 64-bit version of Python 3.5.1, so can't guarantee that numpy for Python 2.7 is already corrected.
I'm not sure if this is a good solution but it removed the error.
I commented out the line:
from numpy._distributor_init import NUMPY_MKL
and it worked. Not sure if this will cause other features to break though
I had the same problem while installing gensim on windows. Gensim is dependent on scipy and scipy on numpy. Making all three work is real pain. It took me a lot of time to make all there work on same time.
Solution:
If you are using windows make sure you install numpy+mkl instead of just numpy.
If you have already installed scipy and numpy, uninstall then using "pip uninstall scipy" and "pip uninstall numpy"
Then download numpy-1.13.1+mkl-cp34-cp34m-win32.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
and install using pip install numpy-1.13.1+mkl-cp34-cp34m-win32.wh
Note: in cp34-cp34m 34 represent the version of python you are using, so download the relevant version.
Now download scipy from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy (appropriate version for your python and system)
and install using "pip install scipy‑0.19.1‑cp34‑cp34m‑win32.whl"
Your numpy and Scipy both should work now.
These binaries by Christoph Gohlke makes it very easy to install python packages on windows. But make sure you download all the dependent packages from there.
I don't have enough reputation to comment but I want to add, that the cp number of the .whl file stands for your python version.
cp35 -> Python 3.5.x
cp36 -> Python 3.6.x
cp37 -> Python 3.7.x
I think it's pretty obvious but still I wasted almost an hour because of this and maybe other people struggle with that, too.
So for me worked version cp36 that I downloaded here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
since I am using Python 3.6.8.
Then I uninstalled numpy:
pip uninstall numpy
Then I installed numpy+mkl:
pip install <destination of your .whl file>
The reason for the error is you upgraded your numpy library of which there are some functionalities from scipy that are required by the current version for it to run which may not be found in scipy. Just upgrade your scipy library using python -m pip install scipy --upgrade. I was facing the same error and this solution worked on my python 3.5.
From your log its clear that numpy package is missing. As mention in the PyPI package:
The SciPy library depends on NumPy, which provides convenient and fast N-dimensional array manipulation.
So, try installing numpy package for python as you did with scipy.
I recently got the same error when trying to load scipy in jupyter (python3.x, win10), although just having upgraded to numpy-1.13.3+mkl through pip.
The solution was to simply upgrade the scipy package (from v0.19 to v1.0.0).
yes,Just reinstall numpy,it works.

Importing opencv and getting numpy.core.multiarray failed to import

Trying to install OpenCV and running into an issue where attempting to import cv2 results in this output -
RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import cv2
ImportError: numpy.core.multiarray failed to import
I'm running on Windows 7 x64, Python v 2.7.9
Thanks!
The error is telling you that you have an out of date version of numpy. If you used pip to install things you can simply run pip install numpy -U, or download the appropriate version from their website.
In case
pip install -U numpy
doesn't work (even with sudo), you may want to make sure you're using the right version of numpy. I had the same "numpy.core.multiarray failed to import" issue, but it was because I had 1.6 installed for the version of Python I was using, even though I kept installing 1.8 and assumed it was installing in the right directory.
I found the bad numpy version by using the following command in my Mac terminal:
python -c "import numpy;print numpy.version;print numpy.file";
This command gave me the version and location of numpy that I was using (turned out it was 1.6.2). I went to this location and manually replaced it with the numpy folder for 1.8, which resolved my "numpy.core.multiarray failed to import" issue. Hopefully someone finds this useful!
I had a similar problem and I solved it by downgrading my numpy version.
What I did was:
pip install opencv-python
pip uninstall numpy
pip install numpy=1.18
This has worked for me using
Python 3.7
opencv-python 4.4.0.46
numpy 1.18.0
linux: sudo apt-get install python-numpy
if you are using ubuntu bionic beaver then try running: sudo apt-get install python-numpy
had the same issue, resolve by running the above command.
Hope it helps
In your environment you can try this command:
conda uninstall numpy
conda install -c conda-forge numpy
I use Python 3.7 # RPI 4.
For opencv to install properly I had to install the listed libraries below.
(Not every package was actually installed, after request)
Regarding Numpy, I think one should stick to the latest version.
For me what worked is to uninstall the existing version 1.16.2 and stick with the current stable 1.21.2.
Stackoverflow topic at missing libraries here: ImportError: libcblas.so.3: cannot open shared object file: No such file or directory.

Cant import numpy on mac OSX mountain lion

I've looked at all the other questions like this and they all seem to be a slight variation of this one in which I can't extract an answer for my problem.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
So I installed it with homebrew into the site-packages directory. At this point in time, importing numpy worked. But then when I had trouble downloading matplotlib, I downloaded the original python 2.7 as opposed to the one that comes on Mac. Now I can't import the module unless I' in the numpy directory, and when I try to build matplotlib it can't find numpy (which is a dependency). Any ideas on what could be wrong?
Third-party add-ons ("distributions") to Python, like numpy, are installed to a particular instance of Python. On OS X 10.8 (Mountain Lion), the Apple-supplied Python 2.7 comes with a version of numpy pre-installed. You can access that python with:
/usr/bin/python2.7
I'm not sure what you mean by "downloaded the original python2.7", but if you installed another version of python, you would need to install another version of numpy using it.
If Your Numpy not install during python 2.7 installation so you can download numpy and install easly from this link install link

Categories

Resources