How to get the correct path to a json file from the customtkinter module

Question:

I made my GUI using customtkinter. I used auto-py-to-exe to make it an file. The exe file doesn’t open because of an theme json file missing error.
The path to the correct file is /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/customtkinter/assets/themes/blue.json.

It caused this error when trying to run the exe file using auto-py-to-exe.
`FileNotFoundError: [Errno 2] No such file or directory: ‘/var/folders/ty/59189mt16kj5vsb0r8s4gjzc0000gn/T/_MEIJFxE4U/customtkinter/assets/themes/blue.json’

The .json theme file for CustomTkinter could not be found.
If packaging with pyinstaller was used, have a look at the wiki:
https://github.com/TomSchimansky/CustomTkinter/wiki/Packaging#windows-pyinstaller-auto-py-to-exe`

I don’t know where this is coming from: /var/folders/ty/59189mt16kj5vsb0r8s4gjzc0000gn/T/_MEIJFxE4U.

I used the code from here: https://github.com/TomSchimansky/CustomTkinter/pull/1191/files. Someone posted this as a fix to this issue but it didn’t fix it.
I used:
`script_directory = os.path.dirname(os.path.abspath(file))

    if theme_name_or_path in cls._built_in_themes:
        customtkinter_directory = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
        with open(os.path.join(customtkinter_directory, "assets", "themes", f"{theme_name_or_path}.json"), "r") as f:
            cls.theme = json.load(f)`

instead of:

`script_directory = os.path.dirname(os.path.abspath(file))

    if theme_name_or_path in cls._built_in_themes:
        with open(os.path.join(script_directory, "../../../assets", "themes", f"{theme_name_or_path}.json"), "r") as f:
            cls.theme = json.load(f)`

It resulted in file not found error. Does anyone know how to change the path correctly to make it match the user’s path? I’m not familiar with the os module, thank you for your help!

Asked By: Darkshadogt

||

Answers:

The issue is caused because your app isn’t being compiled with the appropriate data files. In order to make sure all the correct data files are included with the executable you should use the collect-all feature and input the customtkinter package as it’s value.

If you were using pyinstaller you would add the option --collect-all customtkinter to your command line argument. With auto-py-exe I think it appears as a drop down option somewhere.

Answered By: Alexander