Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyInstaller and pip install locations - Package(s) not found: customtkinter #517

Closed
BootsManOut opened this issue Oct 13, 2022 · 15 comments
Closed
Labels
help wanted Extra attention is needed

Comments

@BootsManOut
Copy link

BootsManOut commented Oct 13, 2022

Hello,

I cannot follow the wiki tutorial for creating the exe file with pyinstaller.
I try to do it via the console directly.

Already when I run
pip show customtkinter
in the console, I get the message: "WARNING: Package(s) not found: customtkinter"

And using the suggested commands with the path to the location of where customtkinter is installed does not work either.
(e.g.: pyinstaller --noconfirm --onedir --windowed --add-data "C:\Users\Username\OneDrive\Desktop\App Files\customtkinter/customtkinter;customtkinter/" main.py or pyinstaller --noconfirm --onedir --windowed --add-data "C:\Users\Username\OneDrive\Desktop\App Files/customtkinter;customtkinter/" main.py)

What can I do to make this work?
I never had issues exporting tkinter apps with other libraries, but I'm not able to make this work in CTkinter, because of the json files.

(btw. I didn't plan to report this, but I might as well mention it here: the dropdown_fg_color argument for the CTkCombobox is not recognized, despite being mentioned in the wiki documentation).

@Akascape
Copy link

Akascape commented Oct 13, 2022

@BootsManOut CustomTkinter is not packaged automatically because it contains some non-python files. So that's why we have to add its folder in add-data manually.

You may be facing other import errors because of different python versions installed. Use the version where customtkinter is installed.

I will recommend you to use Auto-py-to-exe which is an easy interface for Pyinstaller. Try to export the package with that.

@BootsManOut
Copy link
Author

BootsManOut commented Oct 13, 2022

@BootsManOut CustomTkinter is not packaged automatically because it contains some non-python files. So that's why we have to add its folder in add-data manually.

You may be facing other import errors because of different python versions installed. Use the version where customtkinter is installed.

I will recommend you to use Auto-py-to-exe which is an easy interface for Pyinstaller. Try to export the package with that.

Okay, I can try that, but what can I do to find the correct path address, since "pip show customtkinter" is not working?
If I am not able to find the correct path, it won't work with Auto-py-to-exe, either I'm afraid.
Do you know another way to find out the path?
Is it the path to the CTkinter files used by the project? Is it the path where it's generally installed?
Is it somethint else?
And how do I need to format the path? I'm not used to using semicolons as suggested in the wiki (customtkinter;customtkinter/)

@Akascape
Copy link

Akascape commented Oct 13, 2022

@BootsManOut I think you have more than one python version installed.
So you have a different version X installed in your environment. (Where Pyinstaller is installed)

But you have installed customtkinter in a different version Y.

You may be trying to get the module from version X where it is not installed.

You can try to reinstall it properly via pip.

@BootsManOut
Copy link
Author

BootsManOut commented Oct 13, 2022

@Akascape
You said that customtkinter is not in the same folder as pyinstaller.
Do you mean it's not in the same folder as PIP?

How is the fact that customtkinter is not in the same folder as pyinstaller related to the fact that I cannot run the command
'pip show customtkinter'?
Sorry, I'm a bit confused.

@Akascape
Copy link

@BootsManOut If you are unable to find the customtkinter installed path then download the repository zip and extract it. Then you will get the customtkinter folder inside it, just copy its path and use it in -add data

@BootsManOut
Copy link
Author

BootsManOut commented Oct 13, 2022

@Akascape
yeah I think I already tried that.

Is this the correct format for it?:

--add-data "C:\Users\Username\OneDrive\Desktop\App Files\customtkinter/customtkinter;customtkinter/"

or does it need to be :

--add-data "C:/Users/Username/OneDrive/Desktop/App Files/customtkinter/customtkinter;customtkinter/"

or this:

--add-data "C:/Users/Username/OneDrive/Desktop/App Files/customtkinter/customtkinter/"

@Akascape
Copy link

Akascape commented Oct 13, 2022

@Akascape
You said that customtkinter is not in the same folder as pyinstaller.
Do you mean it's not in the same folder as PIP?

How is the fact that customtkinter is not in the same folder as pyinstaller related to the fact that I cannot run the command
'pip show customtkinter'?
Sorry, I'm a bit confused.

@BootsManOut What I mean to say is that if Pyinstaller is installed in version X, it will collect modules from only version X.

You have customtkinter in version Y, so it will not be able to import it from Y.

Thats how Pyinstaller works.

@Akascape
Copy link

@Akascape
yeah that's what I already did.

Is this the correct format for it?:

--add-data "C:\Users\Username\OneDrive\Desktop\App Files\customtkinter/customtkinter;customtkinter/"

or does it need to be :

--add-data "C:/Users/Username/OneDrive/Desktop/App Files/customtkinter/customtkinter;customtkinter/"

or this:

--add-data "C:/Users/Username/OneDrive/Desktop/App Files/customtkinter/customtkinter/"

@BootsManOut I guess third one seems right, but you can get the proper path by clicking the folder properties. Copy that only.

@BootsManOut
Copy link
Author

What I mean to say is that if Pyinstaller is installed in version X, it will collect modules from only version X.

You have customtkinter in version Y, so it will not be able to import it from Y.

Thats how Pyinstaller works.

Well I was able to export the app together with CTkinter the way I usually export apps, but when I run the app it gives me an error file that it could not find the json files that are used to set the color theme in CTkinter. And that error is called from within the CTkinter script, which means it has succesfully been included by pyinstaller into the exe file.
So it's not a version problem.

@Akascape
Copy link

@BootsManOut Otherwise use Auto-py-to-exe, you can easily browse and choose the folders/files. Highly recommended.

@TomSchimansky
Copy link
Owner

If you do python -m pip you get the correct pip version corresponding to the python version you use.
And to chose a specific python version on Windows in the command line you can use the command py -<version>.
So if you use python 3.10 to run your programs you install customtkinter with:

py -3.10 -m pip install customtkinter

And run your program with:

py -3.10 program.py

And then this should also work:

py -3.10 -m pip show customtkinter 

@TomSchimansky
Copy link
Owner

You would install pyinstaller like:

py -3.10 -m pip install pyinstaller

And use it like this:

py -3.10 -m PyInstaller

(note the camel case spelling, for whatever reason)

@TomSchimansky TomSchimansky added the help wanted Extra attention is needed label Oct 13, 2022
@TomSchimansky TomSchimansky changed the title Pyinstaller Export Not working -wiki tutorial not working either. PyInstaller - Package(s) not found: customtkinter Oct 13, 2022
@TomSchimansky TomSchimansky changed the title PyInstaller - Package(s) not found: customtkinter PyInstaller and pip install locations - Package(s) not found: customtkinter Oct 13, 2022
@BootsManOut
Copy link
Author

BootsManOut commented Oct 13, 2022

py -3.10 -m pip show customtkinter

Yes, that's what I needed thanks @TomSchimansky . I got the correct path this way. Installing auto py installer besides not solving the issue, would have just taken away my time.

Now after the json files are included in the exe file, I get another issue with the setuptool module that's used with Ctkinter:

  File "main.py", line 4, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "customtkinter\__init__.py", line 10, in <module>
    from .appearance_mode_tracker import AppearanceModeTracker
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "customtkinter\appearance_mode_tracker.py", line 3, in <module>
    from distutils.version import StrictVersion as Version
  File "_distutils_hack\__init__.py", line 80, in create_module
  File "importlib\__init__.py", line 127, in import_module
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "setuptools\__init__.py", line 10, in <module>
  File "_distutils_hack\__init__.py", line 80, in create_module
  File "importlib\__init__.py", line 127, in import_module
ModuleNotFoundError: No module named 'setuptools._distutils'

Possibly related to this topic.
However I do not have a pyproject.toml file, as part of the mentioned solution in that thread, so it seems I cannot make it work.

What can I do in this situation? Do you think there's a chance you'll ever look into a making the module needing less dependencies for easier export?

@TomSchimansky
Copy link
Owner

Maybe you just need pip install pyinstaller?

@BootsManOut
Copy link
Author

BootsManOut commented Oct 14, 2022

It works now!
So since I had Python 3.9 installed, first I completely re-installed Python as version 3.10.8, and then I updated all the modules of my project, and also updated pip, and then I also ran all the commands you suggested to update pyinstaller etc. And now it works.
Btw. I used this command for the exe creation:
pyinstaller --noconfirm --onefile --windowed --add-data "C:\Users\USERNAME\AppData\Local\Programs\Python\Python310\Lib\site-packages/customtkinter;customtkinter/" --hidden-import=setuptools --hidden-import=_distutils --icon=images/title.ico main.py
So the "onefile" parameter actually worked perfectly fine without problem, despite being mentioned in the wiki that it wouldn't work for the json files.

In any case, thank you very much for your help, @TomSchimansky, I'm happy it works now! Your UI makes the app look so much more professional!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants