Importing error in python package skimage - python

I want to use skimage.restoration.denoise_wavelet to denoise a image. But problem occurs on importing.
from skimage.restoration import denoise_nl_means,denoise_wavelet
ImportError Traceback (most recent call last)
<ipython-input-2-161a32d32528> in <module>()
----> 1 from skimage.restoration import denoise_nl_means,denoise_wavelet
ImportError: cannot import name denoise_wavelet
There is no problem in importing denoise_nl_means which is in the same category with denoise_wavelet. It doesn't make sense.
I used pip for installing and updating the skimage package and jupyter notebook for coding.
I installed all requirements before installing scikit-image 0.12.3. The requirement items I installed were:
matplotlib 1.5.1,numpy 1.11.1,scipy 0.18.1,six 1.10.0,networkx 1.11,pillow 3.4.1,dask 0.10.0,PyWavelets 0.4.0.

As you installed this library with pip, it probably installed the latest stable release, which is something within the 0.12 branch.
There are different documentations for different versions of scikit-learn.
The function which you want to import does not exist yet in any stable branch if we interpret the following correctly:
Search for function-name in docs of development-branch: OK!
Search for function-name in docs of 0.12 branch No hits!
Sadly, the docs of scikit-image do not say when a function was added to the library (as done by scipy).
Further analysis can be done on github + blame here.
So if you need this function, grab the development-branch and install from sources! Always read the corresponding doc-versions!

used the following command:
pip install -U https://github.com/scikit-image/scikit-image/archive/master.zip

Related

ImportError: cannot import name ExponentialSmoothing

I tried to install statsmodels in python. After installation, I checked with pip freeze. The package can be seen in the list.
When I am trying:
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
I am getting error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name ExponentialSmoothing
I have tried the following link also :
link
As of today (10 May 2018), the problem is solved by simply installing version 0.9.0 rather than the default 0.8.0:
pip install statsmodels==0.9.0rc1
I met the same situation, and the install process recommended in Nish's url didn't work for me. Here's how did I solve the problem (I'm using Mac OS).
Remove statsmodels library first, if you have installed: pip uninstall statsmodels
In your terminal, type git init, to initiate git
Then type git clone git://github.com/statsmodels/statsmodels.git
Change the directory to statsmodels using “cd statsmodels”
Next type python setup.py install
python setup.py build_ext --inplace
Now type python in your terminal and then type from statsmodels.tsa.api import ExponentialSmoothing, to see whether it can import successfully
If using conda, this will make statsmodel 0.9.0
conda update statsmodels
It is the wrong import,
Try
from statsmodels.tsa.holtwinters import ExponentialSmoothing, SimpleExpSmoothing, Holt
You can follow the steps mentioned below:
Step 1: Remove statsmodel using pip uninstall statsmodel
Step 2: Install git from here: https://git-scm.com/downloads
Step 3: Follow steps mentioned under "Installing library(statsmodels)" from link mentioned below:
https://www.analyticsvidhya.com/blog/2018/02/time-series-forecasting-methods/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+AnalyticsVidhya+%28Analytics+Vidhya%29

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/

Build developer's version of scipy

I am new and trying to contribute to scipy development. I forked scipy in my github and tried to build it based on this documentation. However, while trying to import scipy in Python, I get the following error:
>>> import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scipy
I also have tried installing all the necessary pre-requirements as mentioned here. I know I can do pip install scipy, but that's not the point of building the developer version of scipy, I guess. Can someone help?
I found this issue: https://github.com/scipy/scipy/issues/5893 which suggest to add scipy in your PYTHONPATH: export PYTHONPATH="$HOME/path/to/scipy/:$PYTHONPATH"
More info on how to do this per different system from scipy documentation (FAQ section):
On Linux and OSX, you can run the command:
$ export PYTHONPATH=$PWD
and on Windows
$ set PYTHONPATH=/path/to/scipy
Another workaround is also suggested in the before-mentioned issue, which is to open the scipy build as a PyCharm project and create a virtual environment within the IDE to use for your coding!
Good luck :)

Python: Why can't I import svm? [duplicate]

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

Unable to locate freeimage after install of mahotas in Python

Hi I am new to Python and am following the Python Image Tutorial.
The following executes with no errors after installing the packages described in the tutorial
import numpy
import scipy
import pylab
import pymorph
import mahotas
from scipy import ndimage
However when I try reading an image
image = mahotas.imread('picture_file.jpg')
I get
image = mahotas.imread('image_file.jpg')
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.6/dist-packages/mahotas-0.6.4-py2.6-linux-i686.egg/mahotas/init.py", line 68, in imread
raise ImportError('mahotas.imread dependends on freeimage. Could not find it. Error was: %s' % e)
ImportError: mahotas.imread dependends on freeimage. Could not find it. Error was: mahotas.freeimage: could not find libFreeImage in any of the following directories:
'/usr/local/lib/python2.6/dist-packages/mahotas-0.6.4-py2.6-linux-i686.egg/mahotas', '/lib', '/usr/lib', '/usr/local/lib', '/opt/local/lib'
I tried installing FreeImagePy and can import it with no problems but it does not help. I have tried adding to the Python path using package sys but not help either.
EDIT: I should have mentioned that all the packages except pymorph and mahotas was installed
on my linux box doing '*sudo apt-get install package_name*' while pymorph and mahotas was installed by downloading and doing 'sudo python setup.py install'.
Answer for more recent versions of mahotas
Mahotas itself does not have the functionality to read in images. imread is just a wrapper around one of 3 backends:
mahotas-imread (i.e., https://pypi.python.org/pypi/imread)
FreeImage
matplotlib (which only supports PNG & JPEG)
Thus, you need to install one of the packages above. Freeimage can be installed on Ubuntu as described below.
If you are running on Windows, you may wish to try Christoph Gohlke’s packages.
Original answer (for older versions of mahotas)
You need to install freeimage to be able to use mahotas.imread (everything else will actually work without it, it's an optional dependency). This is not a Python package per se, just a regular library.
I don't know what distribution you are in, but try looking for a freeimage package. On debian/ubuntu, you can just do:
sudo apt-get install libfreeimage3
You will have a file libfreeimage.so in /usr/lib or in a similar place and everything will work.

Categories