Forums

Cannot import skimage.metrics

I am trying to use

from skimage.metrics import structural_similarity

But I get the following in error logs:

2021-06-03 06:45:04,266: Error running WSGI application
2021-06-03 06:45:04,273: ImportError: /home/vaya/.virtualenvs/ve/lib/python3.8/site-packages/scipy/special/../../scipy.libs/libopenblasp-r0-085ca80a.3.9.so: cannot read file data
2021-06-03 06:45:04,273:   File "/var/www/vaya_pythonanywhere_com_wsgi.py", line 16, in <module>
2021-06-03 06:45:04,274:     from flask_app import app as application  # noqa
2021-06-03 06:45:04,274: 
2021-06-03 06:45:04,274:   File "/home/vaya/mysite/flask_app.py", line 14, in <module>
2021-06-03 06:45:04,274:     from skimage import metrics
2021-06-03 06:45:04,274: 
2021-06-03 06:45:04,274:   File "/home/vaya/.virtualenvs/ve/lib/python3.8/site-packages/skimage/metrics/__init__.py", line 7, in <module>
2021-06-03 06:45:04,274:     from ._structural_similarity import structural_similarity
2021-06-03 06:45:04,274: 
2021-06-03 06:45:04,274:   File "/home/vaya/.virtualenvs/ve/lib/python3.8/site-packages/skimage/metrics/_structural_similarity.py", line 3, in <module>
2021-06-03 06:45:04,274:     from scipy.ndimage import uniform_filter, gaussian_filter
2021-06-03 06:45:04,274: 
2021-06-03 06:45:04,274:   File "/home/vaya/.virtualenvs/ve/lib/python3.8/site-packages/scipy/ndimage/__init__.py", line 153, in <module>
2021-06-03 06:45:04,274:     from .interpolation import *
2021-06-03 06:45:04,274: 
2021-06-03 06:45:04,275:   File "/home/vaya/.virtualenvs/ve/lib/python3.8/site-packages/scipy/ndimage/interpolation.py", line 37, in <module>
2021-06-03 06:45:04,275:     from scipy import special
2021-06-03 06:45:04,275: 
2021-06-03 06:45:04,275:   File "/home/vaya/.virtualenvs/ve/lib/python3.8/site-packages/scipy/special/__init__.py", line 633, in <module>
2021-06-03 06:45:04,275:     from . import _ufuncs
2021-06-03 06:45:04,275: ***************************************************
2021-06-03 06:45:04,275: If you're seeing an import error and don't know why,
2021-06-03 06:45:04,275: we have a dedicated help page to help you debug: 
2021-06-03 06:45:04,275: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-06-03 06:45:04,275: ***************************************************

What could be wrong? I uninstalled and reinstalled scikit. Installed and used different versions of it. Still the same. However, when I only use

import skimage

Then no error is thrown.

BUT at the same time:

from skimage import metrics

gives above error

If you're seeing an import error and don't know why, we have a dedicated help page to help you debug: https://help.pythonanywhere.com/pages/DebuggingImportError/

Just a blind shot, is it missing correct dependency perhaps?

Hi,

I checked the DebuggingImportError page. The paths etc. are all fine and python is looking in the right place for the files/modules. This is confirm since:

import skimage

works, but

from skimage import metrics

does not work

I checked python documentation, metrics in included in current version of skimage. As you can see in error log, it says "cannot read file data" instead of "file not found"' Could you check if metrics is present in that directory?

You can check for yourself by running this bash command:

ls /home/vaya/.virtualenvs/ve/lib/python3.8/site-packages/scipy/special/../../scipy.libs/libopenblasp-r0-085ca80a.3.9.so

However, I'd read that error as suggesting that the library file is corrupted rather than missing. Did you get any errors when you installed packages earlier on? Sometimes if you run out of disk space while installing a package, you can wind up with what is essentially half of a file installed, so of course things won't work properly.

It might be worth deleting your virtualenv ve using rmvirtualenv ve and re-creating it, and re-installing the packages -- that would at least mean that you had a fresh set of installed files.

Thanks for your replies. I dropped what I was trying to do. In future if I need to use the same set of libraries, I will come back to this forum. If it still doesn't work, well, ask a new question!