I've been stuck for hours trying to figure out how I can get Pyinstaller to include images. I've made a small tkinter script which load up some images to display. The program works on my own pc, but I want to be able to download the script on another computer and run it with the pictures working, but I can't figure out how to do that.
I thought I could fix this issue by downloading a folder with the images on another machine and make the script refer to that folder but somehow it's just not working. It works when I run it on my own machine but not when I make it a .exe file with Pyinstaller.
os.chdir(sys.path[0])
path = os.path.dirname(os.path.abspath(__file__)) + r"\pics"
The thought behind the two lines above was that if I download the script on another computer as well as the pictures and insert them into a folder, I could refer to that folder and load them up (as long as the folder is in the same directory as my script) - but this isn't working. I'm clearly overseeing something, please help.
The easiest way is to use the Tree class available in a spec file. See https://pyinstaller.readthedocs.io/en/stable/advanced-topics.html#the-tree-class for the official documentation and https://stackoverflow.com/a/20677118/10475068 for an example of how to use it.
Related
When I do image processing in pycharm, I can't add images from my file explorer in the directory. How should I fix it?
I've done what I can as possible but I'm a starter of python. I wasn't able to solve this. So, I know this's not enough by myself.
Since you're using pycharm you must have created a project folder in a directory
That directory is located at C:\Users<user>\PycharmProjects if you have done default installation this will be visible in file explorer and you could use normal copy paste then
So I'm trying to share my PyQt project. When I download the zip file and extract it, it looks like
If I run app.py from CMD, it will run the app, but without the icon file which is inside of that folder. Inside of the code I do need that file and point to it, so I'm not sure why it doesn't find it automatically. It seems that without it the app doesn't work properly. I was wondering if there's a work around for this issue.
Here is how the app looks when I "open folder" in my IDE:
Here is how it looks when I simply open the .py file, in that same folder:
Anything related to the icons (basically all notifications) are not working when I run it like that.
I'm not sure what why it behaves like this, but I'd like to be able to share the code for anyone to use without them opening the whole folder.
Eventually, I ended up changing how I'm using the paths.
I added this
dirname = os.path.dirname(__file__)
iconFile = os.path.join(dirname, 'icon/icon.png')
So now I'm using iconFile as my path. Seems to fix the issue
I made a program using the pygame module on Python 3 and it works fine within python, but when I try to compile is using py2exe it won't run. (I just get the programName.exe has stopped working error upon trying to run it).
I managed to narrow down this problem to the pygame.font module as when I comment all the lines that use that module everything works fine. I tried to forcefully include the module using the -i flag in py2exe, but it doesn't appear to change anything...
What am I doing terribly wrong?
Edit: I managed to get the reason of the program not working - it crashes as it can not find build\executable.exe\pygame\freesansbold.ttf . What I don't understand is why the hell is the pygame folder supposed to be located in a folder with the name of my executable? (Of course, I can not create a folder with the same name as an existing file in the directory). If anyone has a clue to how to fix it, please help!!
I had the same problem using cx_Freeze, so hopefully this will work for you as well. Open up your pygame package folder. It should be C:\Python34\Lib\site-packages\pygame. There should be a True Type Font File titled freesansbold.ttf. Copy that file then open the folder containing your exe program. There should be a zipped file called library. Open it up and go to the pygame folder inside the zipped file. Should look something like this \build\exe.win32-3.4\library.zip\pygame. And just paste the freesansbold.ttf file in that folder and it should work perfectly.
I managed to find a way! By including -l library.zip argument in the build_exe command and then following the instructions given by DeliriousSyntax in the answer above I managed to get it to work!
Hi i want to build an install creator for my programs in Python.
I have made code for the information gathering, PATHS, FILES, PICS etc.
Now i need to:
Compress the files for the program.
make a config file with install paths ect.
make code for the INSTALLER (i have that to)
Finally i need to "pack" it all in an .exe file that will run the first window in my INSTALLER CODE, so that it will work as my own custom made installer.
Does anybody have any idea how to go about this EASY??
My biggest problem is to collect it all in ONE .exe file that will run my windows(TK code) and of course install my program when clicked...
I have a few ideas how to go about it, BUT in my head these ideas seem to be BIG and NOT EASY, so need ideas for easier solutions.
Update. If i have a program build in python(Tkinter) that will gather the information and save this info as a config file. Then i can build a program that can read this information and extract files ect. accordingly to the info. But how will i combine these configfiles/programs in ONE .exe file that when clicked will run MY program and then accordingly extract my files to the paths in config file. And last use my own icon for the single .exe
If you want to have everything in one exe file, its code needs to be aware of it's content and extract them. This is a problem that has been solved by various tools, eg. see this SO question and its answers.
Hi!I made a chess engine in python which i then compiled to .exe using py2exe. The problem is that it doesn't look very neat when i have all the strange files gathered together in the same folder (dist). I'd like to make a new folder inside the dist folder that contains all the helper files, so all my dist folder contains is the folder holding the helper files and the main launch application. However, i can't simply copy the helper files to a new folder, as the computer doesn't find them then and raises an error.
How can it be solved? Also, i'm using inno setup to make an installation, but i can't figure out how to find a solution there, either.
Thank you very much!
There is a feature in the configuration of py2exe that allows you to bundle all the Python files in a single library.zip file. That would considerably reduce the amount of files in the root directory, but there will still remain some files, regardless of all that.
These files are generally DLL files, at least from what I saw with GUI applications. You cannot remove these, because they are required to launch the application. A workaround to this problem is to create a batch file that will run the actual program which can be in child directory. The point is that these files should either be in the same directory as the executable, or the current working directory, or a path in the PATH environment variable. At least it's the case of most of these. Another approach might be a batch file which will modify the PATH variable or cd to another directory and run the file afterwards
I never tried to do it, so it might break some things for you. Anyway, IMO the best approach is to create an installer and add shortcuts and you won't have to bother with the user messing with these files.
Try using pyinstaller instead. It's easy to use, and will compile your PythonLib and all necessary python files to a stand alone EXE. So you don't have to worry about the having a mess of files in your dist file. (just one single exe).
And if you have other external files, such as databases, text files, csv's. etc... you can set them up to deploy in exactly the fashion you want from the inno setup [Files] section.
I wrote a detailed explanation on this yesterday, so check out this link:
https://stackoverflow.com/a/13259452/1339024
--Edit--
*Make sure you use pyinstaller 1.5 , as the 2.x version doesn't exactly work the same