Reputation: 51
I have a Python script (3.9.8) which work fine in the cli (on Win11). Now I want to take my python script and generate a .exe
. I did it once with hydra without any problems. Now after the convert I do get this error message from Hydra (1.2.0).
Traceback (most recent call last):
File "src\main.py", line 19, in <module>
File "hydra\main.py", line 90, in decorated_main
File "hydra\_internal\utils.py", line 332, in _run_hydra
File "hydra\_internal\utils.py", line 183, in create_automatic_config_search_path
File "hydra\_internal\utils.py", line 196, in create_config_search_path
File "hydra\core\plugins.py", line 46, in instance
File "hydra\core\singleton.py", line 17, in instance
File "hydra\core\singleton.py", line 13, in __call__
File "hydra\core\plugins.py", line 54, in __init__
File "hydra\core\plugins.py", line 58, in _initialize
File "importlib\__init__.py", line 127, in import_module
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'hydra._internal.core_plugins'
This is my project structure
src
│ main.py
│
├───conf
│ │ config.yaml
│ │ __init__.py
│ └───hydra
│ └───job_logging
│ logging.yaml
│
└───logs
I am using the auto-py-to-exe
module. Modules are in an env, I include the path to the site-packages. I am using the version 2.23.1
pyinstaller --noconfirm --onefile --console --paths "D:/Programmieren/Python/StorageRoom/.venv/Lib/site-packages" "D:/Programmieren/Python/StorageRoom/src/main.py"
This is the code I am using which gets me the error.
from omegaconf import DictConfig
import traceback
import sys
import hydra
import logging
@hydra.main(version_base=None, config_path="../conf", config_name="config")
def main(cfg: DictConfig) -> None:
log = logging.getLogger(__file__)
log.info("This is a very nice print from the exe")
if __name__ == "__main__":
try:
main()
except Exception:
print(traceback.format_exc())
sys.exit(-1)
config.yaml
defaults:
- override hydra/job_logging: logging
- _self_
hydra:
output_subdir: null
run:
dir: .
logging.yaml
version: 1
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logFormatter:
format: '%(asctime)s | %(name)s | %(module)s-%(lineno)4s | %(levelname)-8s | %(message)s'
handlers:
console:
class: logging.StreamHandler
formatter: simple
stream: ext://sys.stdout
file:
class: logging.FileHandler
formatter: logFormatter
filename: logs/${hydra.job.name}.log
root:
handlers: [console, file]
level: INFO
disable_existing_loggers: false
This is my output folder structure This is my project structure
output
│ main.exe
│
├───conf
│ │ config.yaml
│ │ __init__.py
│ └───hydra
│ └───job_logging
│ logging.yaml
│
└───logs
Upvotes: 0
Views: 1050
Reputation: 7769
I suspect that there's a bug in auto-py-to-exe
that is incompatible with Python's importlib.import_module
function.
Looking at the stacktrace you posted, I see File "hydra\core\plugins.py", line 58, in _initialize
. Looking at line 58 hydra/core/plugins.py
in the Hydra source repo, I see there's a call to importlib.import_module
.
It seems there is an open issue in the auto-py-to-exe
repo (https://github.com/brentvollebregt/auto-py-to-exe/issues/325), and several closed issues (see e.g. https://github.com/brentvollebregt/auto-py-to-exe/issues/177), that mention trouble with importlib.import_module
.
Upvotes: 0