Skip to content

[BUG] Library Import Fails for Python 3.8 #16

@jlw387

Description

@jlw387

Hi!

I'm currently trying to use this package with Python 3.8.13, but there's an issue with the importlib package, and it errors out when I call import cctk.

Here is the stack trace:

Traceback (most recent call last):
  File "standardize_conformer_protons.py", line 3, in <module>
    import cctk
  File "/Users/.../.venv/lib/python3.8/site-packages/cctk/__init__.py", line 6, in <module>
    from .molecule import Molecule
  File "/Users/.../.venv/lib/python3.8/site-packages/cctk/molecule.py", line 11, in <module>
    from cctk.helper_functions import (
  File "/Users/.../.venv/lib/python3.8/site-packages/cctk/helper_functions.py", line 25, in <module>
    with pkg_resources.files(data).joinpath("isotopes.csv").open() as isotope_file:

The issue comes from helper_functions.py line 25. This line expects pkg_resources to have the attribute files, and it does not. Looking earlier at lines 10 through 14 we see that pkg_resources is just a renaming of importlib.resources or importlib_resources, depending on whether the backport is needed or not. The backport actually works correctly when I modify my local installation to use it regardless of whether importlib.resources is available. However, the Python 3.8 implementation for importlib.resources does NOT have the files() function that is needed for line 25 in helper_functions.py. You can check it here if you don't believe me.

This is not true for later versions of Python - the package importlib.resources DOES have a files attribute. I suspect you refactored the package for later Python versions, and when that happened it broke the package for older versions. I'd also recommend setting up the dependencies

If you want to solve this without doing too much work, I would recommend adding a check for the necessary files attribute and going with the backport version if it isn't available. That said, there are some other dependency issues that I noticed (ex: a separate module pkg_resources used by molecule.py is not being tracked correctly, and I manually have to add it to get the library to function), so you may want to look into a larger cleanup of the dependencies anyways.

Also as a side note, this is almost certainly an issue for Python 3.7 as well, as can be seen in the Python 3.7 implementation on GitHub. I can't confirm this though because my local system does not have a supported binary for Python 3.7.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions