Dragon2fly/logger_tt

Build Exe from "pyinstaller" throws exception

Closed this issue · 3 comments

I am using this package in a multiprocessing python code for Windows. I am able to run my python code of multiprocessing in the python interpreter (PyCharm).
Additionally I am also building my python code (which is using/importing logger_tt) using the pyinstaller package to exe file.

Though I am able to build the exe (using parameter --onefile) as mentioned above. But while executing the exe, it is throwing the exception as follows in the logging module.

Traceback (most recent call last):
File "logging\config.py", line 390, in resolve
AttributeError: module 'logger_tt' has no attribute 'handlers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "logging\config.py", line 392, in resolve
ModuleNotFoundError: No module named 'logger_tt.handlers'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "logging\config.py", line 565, in configure
File "logging\config.py", line 723, in configure_handler
File "logging\config.py", line 399, in resolve
File "logging\config.py", line 392, in resolve
ValueError: Cannot resolve 'logger_tt.handlers.StreamHandlerWithBuffer': No module named 'logger_tt.handlers'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "online_analysis07_MotDet_EmbData_RVS215_222_Prod_Cust_Mode_mp7_log.py", line 39, in
setup_logging(config_path=r"C:\Users\uid42050\AppData\Roaming\Python\Python310-32\site-packages\logger_tt\log_config.json", log_path=str_file_path, use_multiprocessing=True, full_context=1)
File "logger_tt_init_.py", line 182, in setup_logging
File "logging\config.py", line 810, in dictConfig
File "logging\config.py", line 572, in configure
ValueError: Unable to configure handler 'buffer_stream_handler'

hi @81piyush

Can you give minimal reproducible code and config file that you used?
Also which version of pyinstaller you are using?

Thanks.
Looks like on explicitly importing the handlers from logger_tt module in the main file, the issue got resolved.
The updated import statements looks like following.

This was only required while using the exe build from pyinstaller (version: 5.3). Otherwise running directly on the pycharm python interpreter it works fine without it.

Also I had to give the path of config file explicitly as below, because it was not able to find it from the default folder. Though it worked fine without it on the pycharm interpreter.

from logger_tt import setup_logging
from logger_tt import logger
from logger_tt import handlers
str_file_path = time.strftime("Logs/LOG_%Y-%m-%d_%H-%M-%S.log")
setup_logging(config_path=r"C:\Users\ ....

I'm glad that you have solved your problem.

If you don't use buffer_stream_handler, then you could remove it from your config file.
If you do use buffer_stream_handler, since there is no place that explicitly imports logger_tt.handlers, your solution is correct

Because --onefile mode will extract itself into a different temp folder, you will have to bundle the config file with your app too for the relative path to work. Otherwise, using an absolute path is the best.