How to import Scipy and Numpy in Python? - 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

Related

Numpy Import Error in Anaconda Environment using Spyder (WINDOWS)

BACKGROUND
Just two days ago I was able to run any program that had a numpy dependency. Now when I try to run my code using pandas, matplotlib or any module that depends on numpy, I get the below error:
Traceback (most recent call last):
File "<ipython-input-8-8fcf286af663>", line 7, in <module>
import numpy
File "path\to\Python\Python38\site-packages\numpy\__init__.py", line 140, in <module>
from . import core
File "path\to\Python\Python38\site-packages\numpy\core\__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.7 from "C:\ProgramData\Anaconda3\pythonw.exe"
* The NumPy version is: "1.19.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
SETTINGS CHECK
The return message references this site: https://numpy.org/devdocs/user/troubleshooting-importerror.html but nothing there has helped me.
I checked my Path variable to make sure that all the required directory locations are there and there is no issue.
I successfully import numpy when I compile code from cmd using python -c "import numpy; print('done')"
I am using an anaconda environment, the Spyder IDE, and again it was just fine two days ago.
I checked the python version from pythonw.exe and it seems fine as well
What could be wrong with my environment?
ATTEMPTED SOLUTIONS HERE
Also, I've checked the following links with no success:
Importing the numpy c-extensions failed
importing numpy package in Spyder, Python
python Spyder not importing numpy
https://github.com/numpy/numpy/issues/15090
Can't import numpy anaconda
Import error: Anaconda numpy (numpy and Anaconda already installed, virtualenv)
Turns out my problem was very simple. The main solution I was trying was to uninstall and reinstall.
Every time I installed and uninstalled the modules, I did so from the standard command line.
That was wrong since anaconda uses its own virtual environment to store data.
So all I had to do was run this command from the anaconda command prompt:
pip install --upgrade pandas && pip install --upgrade numpy
this command would work just as well:
pip uninstall pandas && pip uninstall numpy && pip install pandas
(since the last install would automatically download any dependencies that pandas has, which is numpy

Scipy Import Error; cannot import name NUMPY_MKL

I used python xy recently with an old lib of scipy (0.15). Because I wanted to use Spherical Voronoi, I had to install a more recent version of scipy. For this I used pip and the unofficial distributions for python modules with wheel. The install worked without error messages. But now, if I try to import scipy by code, I get this error message below. I already unistalled whole python packages so far and instead installed anaconda. But the error message is still the same. I checked my registry (Windows 10) - can't find anything suspicious.
Any idea? Thank you!
test.py
1.12.1
Traceback (most recent call last):
File "test.py", line 11, in <module>
import scipy
File "C:\Users\Boss\AppData\Roaming\Python\Python27\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
Your scipy is built with mkl support and requires mkl support in numpy too. Download numpy from the same site you downloaded scipy (probably Christoph Gohlke's builds). Or if you are using Anaconda use Anaconda packages for both.
Updated - Your error is basically that  numpy+mkl (numpy with Intel math Kernel library) so this is because when you have installed the scipy by precompiled archive, which requires  numpy+mkl but installing numpy using pip won't get you that.
This problem can be easy solved by installation for numpy+mkl from whl file from - http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Old - This is due to the improper installation of numpy, I've had this error few days ago and then I had to install the numpy again. So, upgrade pip and then try installing the numpy whl again. It just worked for me.
Get it here -https://pypi.python.org/pypi/numpy
even this has almost everything - http://www.lfd.uci.edu/~gohlke/pythonlibs/

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.

Unable to import numpy

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

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