1

I have developed Python program using YOLOV8 algorithm to detect human entry and it works perfectly in pycharm. when i convert it to exe file using pyinstaller im getting following error. Can anyone please help me out to resolve this issue?
File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module File "ultralytics\utils\__init__.py", line 265, in <module> LOGGER = set_logging(LOGGING_NAME, verbose=VERBOSE) # define globally (used in train.py, val.py, predict.py, etc.) File "ultralytics\utils\__init__.py", line 233, in set_logging if WINDOWS and sys.stdout.encoding != 'utf-8': AttributeError: 'NoneType' object has no attribute 'encoding'

I tried to convert python with ultralytics file to exe file, and run it independantly in any PC.

1

1 Answer 1

1

I am not sure if this is the optimal solution but after hours of research and trial/error runs, here is how I managed to get around this issue:

  1. In Pycharm enter "Ctrl+Shift+N". In the box, enter "ultralytics/utils/innit.py" (innit should have 2 underscores on both sides)

  2. Once you locate and open the source file, you need to change 2 things:

    a. Add these 2 lines at line #233

    sys.stdout = open(os.devnull, "w")

    sys.stderr = open(os.path.join(os.getenv("TEMP"), "stderr- "+os.path.basename(sys.argv[0])), "w")

    b. In line #37, change DEFAULT_CFG_PATH to `DEFAULT_CFG_PATH = "default.yaml" # changes it to working directory so .exe does not keep looking for it.

  3. Before freezing with Pyinstaller, make sure you place a copy of "default.yaml" to your working directory on Pycharm: https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/default.yaml

  4. I used this command to freeze my code: pyinstaller --onefile --windowed --add-data="best.pt;." --add-data="default.yaml;." main.py -->You need to make sure you add default.yaml explicitly like you would your best weights.

  5. When .exe is created, make sure that "default.yaml" is present in whichever directory you will run the executable.

    6.This last step may not be necessary in your case but it was in my case. The executable was run multiple times when an inference was made with the model through the GUI. I added:

    from multiprocessing import freeze_support

     if __name__ == "__main__":
    
         freeze_support()
    

right after my import statements and that took care of it. Again, the above is a compilation of solutions I scrapped from here and there and may not be the best path but it got me to the end. Hope it helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.