Cannot import name 'Enum'
Opened this issue · 4 comments
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
Locally I solved renaming enum.py in my_enum.py and changing all "from .enum import" into "from .my_enum import"
(and also "from ..enum" in backend/schemas/entity.py
I can make you a pull request if this naming convention is good...
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 😉
TBH, I'd prefer to convert the backend
directory into a Python package with a meaningful name and a setup.py