I'm having this problem:
File "C:\IntelPython3\lib\site-packages\scipy\ndimage\filters.py", line 37, in
from . import _nd_image
ImportError: cannot import name '_nd_image'
I was checking in that path and i can't find any module or something called nd_image but i've looked for all the scipy releases and i can't find it too.
Can someone help please? (WINDOWS)
You might be using the older version of scipy with the latest version of python.
You should upgrade scipy to solve the problem by typing below command line.
pip install --upgrade scipy
If you are not using pip in Window, you can use conda or other things.
And actually, you can not find _nd_image.py module. This question might be helpful.
Related
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
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
Using Python 2.7 with scikit-learn 0.14 package. It runs well on some examples from the user guild expect the Linear Models.
Traceback (most recent call last):
File "E:\P\plot_ols.py", line 28, in <module>
from sklearn import datasets, linear_model
File "C:\Python27\lib\site-packages\sklearn\linear_model\__init__.py", line 12, in <module>
from .base import LinearRegression
File "C:\Python27\lib\site-packages\sklearn\linear_model\base.py", line 29, in <module>
from ..utils.sparsefuncs import mean_variance_axis0, inplace_column_scale
ImportError: cannot import name inplace_column_scale
Thank you~
I was able to fix this by going to my python folder and deleting the file:
python27\Lib\site-packages\sklearn\utils\sparsefuncs.pyd
My guess is that the problem was:
An older version of scikit-learn implemented sparsefuncs as a windows DLL
The current version implements it as a python file
If you install a new version on top of an old version it does not delete the old DLL
When you try to import, Python uses the pyd in preference to the py implementation
But the old implementation did not include this function
This suggests that there might be bigger problems caused by installing a new version and it might be wise to delete the whole sklearn directory before reinstalling the new version.
I encountered the same issue in Mac Os.
I solved it by deleting the file manually:
rm /usr/local/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so
Uninstalling scikit-learn and reinstalling it was the only option that worked for me:
pip uninstall scikit-learn
pip install scikit-learn
I solve this problem by :
pip uninstall scikit-learn
and don't forget to rm the 'sklearn' folder in the python 'site-packages'
rm -rf /path/Python-2.7.5/lib/python2.7/site-packages/sklearn/
then reinstall the package:
pip install scikit-learn
On a related note, this has been posted as a bug on the official Github page, along with some additional solutions, basically suggesting the same solutions as above. Long story short: run a make clean to get rid of the .so file.
I had the same problem. I had originally installed scikit-learn by:
sudo apt-get install python-sklearn
When none of the other solutions posted here worked, I decided to uninstall my version of scikit-learn and reinstall it:
pip2 install --user --install-option="--prefix=" -U scikit-learn
Used pip2 because I have two versions of python, so I use scikit-learn in Python 2.7
same problem happened with can not import _safe_split, have a look
http://stackoverflow.com/questions/41024001/importerror-cannot-import-name-safe-split
https://github.com/scikit-learn/scikit-learn/issues/7582
EDIT: check comment by Andreas Mueller
Whenever I use Pyplot
import matplotlib.pyplot as plt
I got this problem. It shouldn't be installed the right way
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/_path.so, 2): Symbol not found: ___sincos_stret
Referenced from: /Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/_path.so
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/_path.so
any ideas on how to solve this problem.
Are you using MAC OSX 10.9? If not, it may be that you've installed the wrong version for your matplotlib. In my case, ScipySuperpack installed the wrong version for me although I followed precisely the instruction for Mac OSX 10.8.
If this is your problem, you may solve it through the steps below:
Download the older version of SpicySuperpack in zip format (in my case, through https://github.com/fonnesbeck/ScipySuperpack/archive/10.8_final.zip#).
Uninstall the old matplolib by typing: pip uninstall matplotlib.
Unzip the downloaded ScipySuperpack, if it has not been unzipped yet.
Go to the ScipySuperpack folder and type: easy_install matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg (use a different file name if this is not the one included in your downloaded ScipySuperpack folder)
Note: If you are using virtualenv, just activate your virtual environment before doing the easy_install.
Hope it helps!
If pip uninstall/install doesn't work, you might even have to go deeper. Do you get the same error with other modules within matplotlib or other modules in general from Python?
My suggestion, as you are on OSX, is to use homebrew to manage the installation of Python and pip and then everything should work much smoother.
Easiest is
pip uninstall matplotlib
pip install matplotlib
You may even have to go further to do the same with numpy.
There is some important information regarding getting matplotlib running on OS-X here most significantly:
"Which python for OS X?
Apple ships with its own python, and many users have had trouble with it. There are several alternative versions of python that can be used. If it is feasible, we recommend that you use the enthought python distribution EPD for OS X (which comes with matplotlib and much more). Also available is MacPython or the official OS X version from python.org.
"
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.