Pyinstaller exectuable using data from other folders?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Pyinstaller exectuable using data from other folders?



I've written a program that generates a random name and displays a random image along with it using Python and tkinter. However, I want the user to be able to add and remove pictures as well as edit the names of students. That being said, I don't want to package these inside the executable where it can't be changed by the user.



To use PyInstaller, I go into the command prompt and navigate to the working directory and type:


pyi-makespec --windowed --onefile --icon=Assets\icon.ico random_student.py



Then, in the spec file I change datas to:


datas=[('Assets\icon.ico', 'Assets')],



Then, I run


pyinstaller random_student.spec



The program runs just fine using PyCharm. And I've done this exact same method on a couple of other .py files an it works. However, they don't need to pull images/text into their programs. This will create an executable, but I can't run it. It gives me a Fatal Error "Failed to execute script random_student". I've tried placing the executable in the working directory and in the pictures folder, but neither work.



I'm currently using Windows 10 64-bit and Python 3.6.6



I'd appreciate any kind of help I can get with this!



SOLUTION: I removed the --windowed option so I could actually read the error. Then realized I didn't have Pillow installed so it was unable to be packaged. Thank you for the help.





Could you please remove the --windowed argument in the pyinstaller command? This will allow you to see the console output. However the console may open and close really quickly. In this case I suggest to open cmd, cd to the directory with your exe and the running the exe. This will prevent the output to be hidden for us.
– Jakub Bláha
Aug 10 at 20:21


--windowed


cd





Thanks, I should have thought of that... C:UserstomalDesktopProgramsrandom_student>random_student.exe Traceback (most recent call last): File "random_student.py", line 4, in <module> from PIL import Image ModuleNotFoundError: No module named 'PIL' [6716] Failed to execute script random_student So it seems for some reason PIL isn't being loaded up. Any ideas on how to fix that? I haven't tried any other scrips that use PIL.
– Thomas Kellough
Aug 10 at 20:27






Add 'PIL' (maybe 'Pillow') to hidden_imports in the spec file.
– Jakub Bláha
Aug 10 at 20:32



'PIL'


'Pillow'


hidden_imports





Welcome to StackOverflow! Please edit your original post to add the text requested in the comment. Also, please avoid posting to external images, which when deleted, will render this post meaningless. The point of SO is to create a lasting encyclopedia of questions and answers, and to help people later who have similar issues. Thanks!
– Jeff Learman
Aug 10 at 20:33





I got it working! I'm so sorry guys, it was such an easy solution. I forget I reinstalled Python the other night and forgot to install pillow again. Since I usually run my scripts from PyCharm I had it installed there, but not outside of the PyCharm directory. Thank you so much. I at least learned the tip about NOT using --windowed to see what's actually occuring.
– Thomas Kellough
Aug 10 at 20:35









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard