Why does first import of skimage fail, but second one succeed? - python

When I import skimage, I get an odd error message that seems to be connected to version mismatch issues with scikit-image, numpy and dask, but if I immediately try to import again, everything is fine -- i.e.
(base) me#balin:~$ python
Python 2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 19:04:19)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import skimage
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/anaconda2/lib/python2.7/site-packages/skimage/__init__.py", line 167, in <module>
from .util.dtype import (img_as_float32,
File "/home/me/anaconda2/lib/python2.7/site-packages/skimage/util/__init__.py", line 6, in <module>
from .apply_parallel import apply_parallel
File "/home/me/anaconda2/lib/python2.7/site-packages/skimage/util/apply_parallel.py", line 8, in <module>
import dask.array as da
File "/home/me/anaconda2/lib/python2.7/site-packages/dask/array/__init__.py", line 9, in <module>
from .routines import (take, choose, argwhere, where, coarsen, insert,
File "/home/me/anaconda2/lib/python2.7/site-packages/dask/array/routines.py", line 256, in <module>
#wraps(np.matmul)
File "/home/me/anaconda2/lib/python2.7/functools.py", line 33, in update_wrapper
setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'numpy.ufunc' object has no attribute '__module__'
>>> import skimage
>>>
>>> skimage.__version__
'0.14.2'
>>> import numpy as np
>>> np.__version__
'1.16.2'
>>> import dask
>>> dask.__version__
u'1.0.0'

These versions of dask and numpy are incompatible, apparently. There are multiple bug reports about this
https://github.com/scikit-image/scikit-image/issues/3649
https://github.com/scikit-image/scikit-image/issues/3654
https://github.com/scikit-image/scikit-image/issues/3818
The solution seems to be updating dask, so maybe try
conda update --no-update-deps dask

Related

Unable to import statsmodels

I am new to python and I am trying to learn how to use it for statistics. I have been trying to use the
from statsmodels.stats.weightstats import ztest
But I get an error when I try to use this command.
Here is what it displayed:
Python 2.7.17 (default, Nov 7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from statsmodels.stats.weightstats import ztest
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/stats/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/__init__.py", line 1, in <module>
from .tools import add_constant, categorical
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/tools.py", line 8, in <module>
from statsmodels.compat.python import lzip, lmap
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/_testing.py", line 11, in <module>
from statsmodels.compat.pandas import assert_equal
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/pandas.py", line 4, in <module>
import numpy as np
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/numpy.py", line 46, in <module>
NP_LT_114 = LooseVersion(np.__version__) < LooseVersion('1.14')
AttributeError: 'module' object has no attribute '__version__'
>>>
Any help that I can get would be appreciated. I am using python 2.7.17
I'm also working on python 2.7 facing exactly the same problem.
Here's how I solved it:
First thing first, it says in error message
NP_LT_114 = LooseVersion(np.version) < LooseVersion('1.14')
Thus make sure you have numpy version > 1.14
Secondly, I downgraded statsmodels from 0.11.0 to 0.10.0.
Hope it works for you too.
(numpy==1.16.5, statsmodels==0.10.0, python=2.7)
Just had this issue after conda chose to update numpy from 1.13.3 to 1.14.3. Reverting numpy via procedure in http://blog.rtwilson.com/conda-revisions-letting-you-rollback-to-a-previous-version-of-your-environment/ sufficed to recover functionality, followed by pinning the version in the environment.
also wondering what does shows:
import numpy; print(numpy.__file__)

Python: errors loading numpy and matplotlib

This is an odd problem. I have Python script which imports numpy and matplotlib.
If I put those scripts into /usr/local/bin, I can load the modules and run my scripts with no problem.
But if I have those scripts in my "work" directory, I get errors.
This is also true if I use python in interactive mode:
$ pwd
/usr/local/bin
$ python
Python 2.7.12 (default, Oct 10 2016, 12:56:26)
[GCC 5.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import matplotlib
>>>
No problems.
However, if I go to my work directory, I have problems:
$ pwd
/home/Administrator/Documents/Projects/MOCC/rads
$ python
Python 2.7.12 (default, Oct 10 2016, 12:56:26)
[GCC 5.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/site-packages/numpy/core/__init__.py", line 46, in <module>
from numpy.testing import Tester
File "/usr/lib/python2.7/site-packages/numpy/testing/__init__.py", line 13, in <module>
from .utils import *
File "/usr/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
from tempfile import mkdtemp
File "/usr/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/cygdrive/c/Users/Administrator/Documents/Projects/MOCC/rads/io.py", line 63, in <module>
SEEK_CUR = 1
File "/cygdrive/c/Users/Administrator/Documents/Projects/MOCC/rads/io.py", line 58, in main
AttributeError: 'module' object has no attribute 'loadtxt'
This is cygwin on MS Windows.

TensorFlow error: funcsigs module doesn't have signature attribute

I have installed TensorFlow and wanted to check the installation. Here is the interaction with the python console.
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 106, in <module>
from tensorflow.python.platform import test
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/python/platform/test.py", line 81, in <module>
import mock # pylint: disable=g-import-not-at-top,unused-import
File "/home/shehab1/.local/lib/python2.7/site-packages/mock/__init__.py", line 2, in <module>
import mock.mock as _mock
File "/home/shehab1/.local/lib/python2.7/site-packages/mock/mock.py", line 81, in <module>
inspectsignature = funcsigs.signature
AttributeError: 'module' object has no attribute 'signature'
>>>
Could anyone please tell what I am doing wrong? Thanks.
As Yaroslav noted, this is most likely from running too old a version of Python, or you don't have the funcsigs package installed. For the latter, try pip install funcsigs

Importing Matplotlib.pyplot: DLL load failed

When trying to import matplotlib.pyplot (in Spyder), I get the following error(s):
Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy as sp
>>> import numpy as np
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\pyplot.py", line 36, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\figure.py", line 35, in <module>
from matplotlib import _image
ImportError: DLL load failed: Operation did not complete successfully because the file contains a virus or potentially unwanted software.
If I try to import it again, I get the following:
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\pyplot.py", line 36, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\figure.py", line 35, in <module>
from matplotlib import _image
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\_image.py", line 7, in <module>
__bootstrap__()
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\_image.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
File "C:\Users\...\Anaconda3_1\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
My version of Python is the following:
Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC v.1900 64 bit (AMD64)]
I'm guessing this is a false positive by my antivirus (Avast), though I still get the second error after turning it off. Reinstalling the module or Anaconda did not work either.
Is it possible that my antivirus keeps deleting the DLL, and if so, is there a way to stop it from doing so? Or is my problem something else entirely?
Many thanks!
I had this exact same problem with Avast and matplotlib. My solution was to uninstall Anaconda, then reinstall the same version and add C:\Anaconda3 to the excepted scan directory in Avast.

Occasional error of import matplotlib

In a newly created terminal, I can import matplotlib with no error. After working for some time in the terminal, however, the following happens:
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Usage: example.py torrentfile.torrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py", line 134, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/rcsetup.py", line 19, in <module>
from matplotlib.colors import is_color_like
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/colors.py", line 54, in <module>
import matplotlib.cbook as cbook
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/cbook.py", line 15, in <module>
import new
File "new.py", line 12, in <module>
with open(sys.argv[1], 'rb') as fh:
IndexError: list index out of range
What's wrong?
With the help of #CaptainMurphy and #IronManMark20, I discovered new.py and new.pyc under ~/temp, which shadows some matplotlib files. After removing them, the problem is solved.

Categories

Resources