Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'file_hash' from 'pooch.utils' #252

Closed
AlexanderJuestel opened this issue Aug 23, 2021 · 7 comments · Fixed by #257
Closed

ImportError: cannot import name 'file_hash' from 'pooch.utils' #252

AlexanderJuestel opened this issue Aug 23, 2021 · 7 comments · Fixed by #257

Comments

@AlexanderJuestel
Copy link
Contributor

Description of the problem

As Pooch was updated today, I get an import error for 'file_hash'. See also https://github.com/cgre-aachen/gemgis/runs/3401104133?check_suite_focus=true#step:6:37. Was it maybe moved?

Full error message

ImportError: cannot import name 'file_hash' from 'pooch.utils'

System information

  • Operating system: Win 10
  • Python installation (Anaconda, system, ETS): Anaconda
  • Version of Python: 3.9
  • Version of this package: latest from pip
  • If using conda, paste the output of conda list below:
output of conda list

PASTE OUTPUT OF CONDA LIST HERE

@welcome
Copy link

welcome bot commented Aug 23, 2021

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible.

You might also want to take a look at our Contributing Guide and Code of Conduct.

@leouieda
Copy link
Member

Hi @AlexanderJuestel it was moved internally. The utils module itself is not technically a part of our API and we advise everyone to only use what is documented here: https://www.fatiando.org/pooch/latest/api/ In this case, the correct use would be from pooch import file_hash (without utils). This should work across all versions.

The docs on that page could definitely be clearer on this. I opened #253 to help resolve this. Thanks for posting so quickly!

@leouieda
Copy link
Member

I'll leave this open for now in case anyone else comes across the same issue.

@banesullivan
Copy link

The import path change has broken the import of scikit-image as well 😨

Specifically, I see the error coming from skimage/data/__init__.py:64: ImportError


    """Standard test images.

    For more images, see

     - http://sipi.usc.edu/database/database.php

    """
    from distutils.version import LooseVersion
    from warnings import warn
    import numpy as np
    import shutil

    from ..util.dtype import img_as_bool
    from ._binary_blobs import binary_blobs
    from ._registry import registry, legacy_registry, registry_urls

    from .. import __version__

    import os.path as osp
    import os

    __all__ = ['data_dir',
               'download_all',
               'astronaut',
               'binary_blobs',
               'brain',
               'brick',
               'camera',
               'cat',
               'cell',
               'cells3d',
               'checkerboard',
               'chelsea',
               'clock',
               'coffee',
               'coins',
               'colorwheel',
               'eagle',
               'grass',
               'gravel',
               'horse',
               'hubble_deep_field',
               'human_mitosis',
               'immunohistochemistry',
               'kidney',
               'lbp_frontal_face_cascade_filename',
               'lily',
               'lfw_subset',
               'logo',
               'microaneurysms',
               'moon',
               'page',
               'text',
               'retina',
               'rocket',
               'shepp_logan_phantom',
               'skin',
               'stereo_motorcycle']

    legacy_data_dir = osp.abspath(osp.dirname(__file__))
    skimage_distribution_dir = osp.join(legacy_data_dir, '..')

    try:
>       from pooch.utils import file_hash
E       ImportError: cannot import name 'file_hash' from 'pooch.utils' (/opt/django-project/.tox/test-rgd-client/lib/python3.8/site-packages/pooch/utils.py)

LooseVersion = <class 'distutils.version.LooseVersion'>
__all__    = ['data_dir', 'download_all', 'astronaut', 'binary_blobs', 'brain', 'brick', ...]
__builtins__ = <builtins>
__cached__ = '/opt/django-project/.tox/test-rgd-client/lib/python3.8/site-packages/skimage/data/__pycache__/__init__.cpython-38.pyc'
__doc__    = 'Standard test images.\n\nFor more images, see\n\n - http://sipi.usc.edu/database/database.php\n\n'
__file__   = '/opt/django-project/.tox/test-rgd-client/lib/python3.8/site-packages/skimage/data/__init__.py'
__loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x7f5cd669df10>
__name__   = 'skimage.data'
__package__ = 'skimage.data'
__path__   = ['/opt/django-project/.tox/test-rgd-client/lib/python3.8/site-packages/skimage/data']
__spec__   = ModuleSpec(name='skimage.data', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f5cd669df10>, origin=....py', submodule_search_locations=['/opt/django-project/.tox/test-rgd-client/lib/python3.8/site-packages/skimage/data'])
__version__ = '0.18.2'
binary_blobs = <function binary_blobs at 0x7f5cc64d68b0>
img_as_bool = <function img_as_bool at 0x7f5cc64b5a60>
legacy_data_dir = '/opt/django-project/.tox/test-rgd-client/lib/python3.8/site-packages/skimage/data'
legacy_registry = {'data/astronaut.png': '88431cd9653ccd539741b555fb0a46b61558b301d4110412b5bc28b5e3ea6cb5', 'data/brick.png': '7966caf3...3d5690fc7e3648f2795d730c23a', 'data/cell.png': '8d23a7fb81f7cc877cd09f330357fc7f595651306e84e17252f6e0a1b3f61515', ...}
np         = <module 'numpy' from '/opt/django-project/.tox/test-rgd-client/lib/python3.8/site-packages/numpy/__init__.py'>
os         = <module 'os' from '/usr/local/lib/python3.8/os.py'>
osp        = <module 'posixpath' from '/usr/local/lib/python3.8/posixpath.py'>
registry   = {'color/tests/ciede2000_test_data.txt': '2e005c6f76ddfb7bbcc8f68490f1f7b4b4a2a4b06b36a80c985677a2799c0e40', 'color/tes...24c7', 'color/tests/data/lab_array_d50_2.npy': '4aa03b7018ff7276643d3c082123cf07304f9d8d898ae92a5756a86955de4faf', ...}
registry_urls = {'data/brain.tiff': 'https://gitlab.com/scikit-image/data/-/raw/master/brain.tiff', 'data/cells3d.tif': 'https://gitla...eagle.png', 'data/kidney.tif': 'https://gitlab.com/scikit-image/data/-/raw/master/kidney-tissue-fluorescence.tif', ...}
shutil     = <module 'shutil' from '/usr/local/lib/python3.8/shutil.py'>
skimage_distribution_dir = '/opt/django-project/.tox/test-rgd-client/lib/python3.8/site-packages/skimage/data/..'
warn       = <built-in function warn>

../../.tox/test-rgd-client/lib/python3.8/site-packages/skimage/data/__init__.py:64: ImportError

Considering some high impact projects like scikit-image are now broken on import, it may need to be added back...

@banesullivan
Copy link

scikit-image/scikit-image#5528

@leouieda
Copy link
Member

😭

@leouieda
Copy link
Member

Scikit-image fixed this in scikit-image/scikit-image#5529 and will make a new release to address the issue. We definitely need to be more careful when moving things around in Pooch in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants