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

Cannot import name 'Enum' #137

Open
thesp0nge opened this issue May 5, 2023 · 4 comments
Open

Cannot import name 'Enum' #137

thesp0nge opened this issue May 5, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@thesp0nge
Copy link
Member

During the aimaas security audit I tried to create a testing environment with a database and 2 docker images as from the READM file.

Executing step 3.ii (create a virtual environment) resulted in an import error:

~/Documents/bsc#1210726_aimaas/aimaas/backend master* ❯ python3 -m venv environment
Traceback (most recent call last):
  File "/usr/lib64/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib64/python3.10/runpy.py", line 146, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib64/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/usr/lib64/python3.10/venv/__init__.py", line 7, in <module>
    import logging
  File "/usr/lib64/python3.10/logging/__init__.py", line 26, in <module>
    import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
  File "/usr/lib64/python3.10/re.py", line 124, in <module>
    import enum
  File "/home/paolo/Documents/bsc#1210726_aimaas/aimaas/backend/enum.py", line 1, in <module>
    from enum import Enum, auto
ImportError: cannot import name 'Enum' from partially initialized module 'enum' (most likely due to a circular import) (/home/paolo/Documents/bsc#1210726_aimaas/aimaas/backend/enum.py)

It seems, from this answer 1, that the problem is having a file named enum.py

@thesp0nge thesp0nge added the bug Something isn't working label May 5, 2023
@thesp0nge
Copy link
Member Author

Locally I solved renaming enum.py in my_enum.py and changing all "from .enum import" into "from .my_enum import"

@thesp0nge
Copy link
Member Author

(and also "from ..enum" in backend/schemas/entity.py

I can make you a pull request if this naming convention is good...

@crazyscientist
Copy link
Collaborator

crazyscientist commented May 5, 2023

You could try to create the venv when your CWD is the repo root. You don't need to cd into the backend directory to do that 😉

@crazyscientist
Copy link
Collaborator

TBH, I'd prefer to convert the backend directory into a Python package with a meaningful name and a setup.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants