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

AttributeError: module 'importlib' has no attribute 'util' #1074

Open
kta-intel opened this issue Oct 1, 2024 · 0 comments
Open

AttributeError: module 'importlib' has no attribute 'util' #1074

kta-intel opened this issue Oct 1, 2024 · 0 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@kta-intel
Copy link
Collaborator

Description
When attempting to import the util submodule from the importlib module, an AttributeError is raised. This is problematic as openfl has a few importlib.util calls.

One example:

Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from openfl.federated import PyTorchDataLoader
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "openfl/federated/__init__.py", line 9, in <module>
    from openfl.federated.data import DataLoader  # NOQA
  File "openfl/federated/data/__init__.py", line 12, in <module>
    if importlib.util.find_spec("tensorflow") is not None:
AttributeError: module 'importlib' has no attribute 'util'

Note 1 : it does not seem to be triggered when calling fx commands through fx (i.e. fx plan initialize does not seem to trigger the error even though the dataloader is called during this command)

Note 2 : I have only been able to reproduce it when I install openfl via pip install . as opposed to pip install -e .

Steps to reproduce the behavior:

  1. python3.10 -m venv venv
  2. source venv/bin/activate
  3. git clone https://github.com/securefederatedai/openfl.git
  4. cd openfl
  5. pip install .
  6. enter python console: python
  7. from within python console: from openfl.federated import PyTorchDataLoader

You should see the above error

Expected behavior
PyTorchDataLoader should import with no error

Proposed resolution
Seems best known practice for using importlib.util is to import the submodule directly with import importlib.util
Doing this throughout the repo where import importlib is called should avoid this and similar issues in the future

@kta-intel kta-intel added the good first issue Good for newcomers label Nov 8, 2024
@tanwarsh tanwarsh self-assigned this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants