Pyinstaller's 'onedir' mode creates too many files - python

I am "compiling" my Python application for Windows with PyInstaller 2.1. I initially tried using onefile mode, but onefile takes a long time to startup (decompressing wx and matplotlib). With the onedir mode it's pretty fast (only a little bit slower than native python).
So I want to use onedir mode for faster startup times, but for the end-user it's difficult to find the actual *.exe file inside the huge amount of files located in the main directory (there are 98 files including the actual executable and it's manifest).
I want to make sure a non tech-savvy user can easily "double-click" the executable and work with this program (ease and portability) without a long disclaimer to "just ignore" the 97 other files there.
Is it possible to move all those "distracting" files into a subfolder? Or are there other ways to make it easy for the end-user to run this program?

maybe you could use onedir. The resulting folder you can put anywhere and create a shortcut to the user where it is more comfortable.

Easiest way to reduce the number of files created in --onedir mode would be to create a virtual environment and install only the necessary modules.

You could use some software to pack it into a one-file installer, such as Inno setup.
You could also try to delete some files one by one (if the executable fails just undelete it). I figured out that almost half of the files can be deleted with the executable working fine.
Download Inno Setup from here.

Related

Creating an executable kivy app and exe installer

I created a data-miner GUI for twitter with kivy and am currently having a lot of trouble turning it into an exe. I tried following this video and import glew and sdl2 into my spec but after doing pyinstaller main.spec, my executable still would not open.
Is it because I have more than one files and folders for my program (here is the link to the github repo for my project), if so, how do you deal with that?
In addition, if I manage to success create a working exe, how do I create an exe installer that other people can use to install the executable?
Making an executable from a complex script like yours may become quite frustrating because of its dependencies. But I'm giving you a brief guide about what you need to follow to achieve your goal.
Create your main.spec file with console-mode enabled to see the exact error message for the app. (make sure to remove --noconsole from PyInstaller command or set console=True in spec file). Also use --no-upx in the build command to remove compression from output file (this helps with omitting some DLLs which may cause issues).
You need to make sure that every external module you used can pack correctly. I don't think you get any problem with either Kivy or Tweepy. But if you get any missing import error, try to check the solution for each one by searching the pattern [module] pyinstaller.
Your app has external resources like images, files, etc., which must be added to the packed executable and load properly. I wrote an answer about this here.
If you want a standalone executable, you need to use -F with PyInstaller command, which is more robust than using an installer to gather files in one directory mode.

Make a Python app package/install for Mac

I have developed an application for a friend. Aplication is not that complex, involves only two .py files, main.py and main_web.py, main being the application code, and _web being the web interface for it. As the web was done later, it's kept in this format, I know it can be done with one app but not to complicate it too much, I kept it that way. Two two communicate with some files, and web part uses Flask so there's "templates" directory too.
Now, I want to make a package or somehow make this easier for distribution, on a OSX system. I see that there is a nice py2app thingy, but I am running Windows and I can't really use it since it won't work on Win. I also don't know will py2app make problems since some configs are in text files in the directory, and they change during the runtime.
So, I am wondering, is there any other way to make a package of this, some sort of setup like program, or maybe some script or something? Some simple "way" of doing this would be to just copy the files in the directory in the "Documents", and add some shortcuts to the desktop to run those two apps, and that would be it, no need for anything else. DMG would be fine, but not mandatory.
I believe what you are looking for is to add: #!/usr/bin/python to the first line of your code will allow your friend to just double click on the file and it should open. Just as a warning osx does not tell us what version and as such what version of python and what standard libraries are going to be present.
Also, just make sure that if they have played around with their settings to much and they double click on python it does not work they will have to choose to open the file in "terminal.app" in the Utilities Applications folder (/Applications/Utilities/terminal.app)
The other idea is borrow a mac and compile it with the py2app program that you already mentioned. Otherwise there is no generic binary file that you will be able to compile in windows and have run on mac.

How to put files in folders using py2exe.

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

Python 3 project into exe?

I've made my first Python program, using Python 3.2. Now I'm trying to figure out how to make it an executable.
I pretty much only need it for Windows only. I've searched as much as possible and found out that py2exe doesn't support Python 3. cxfreeze does, but I can't figure out how to make a single executable of my program with it. I need it as a portable one-file exe.
Please bear with me as I am a total newcomer :) Any help is appreciated.
You can use cxfreeze to make the executable (and other files it creates), compress them into a *.7z archive using 7-zip, then use 7-ZIP SFX Maker to turn it into a self extracting archive.
When creating the SFX archive, configure it so that the main executable cxfreeze generates runs when the files are extracted. You can also change the archives icon, as well as tell the archive to extract and run from a temporary folder.
When the user runs the exe, the files will extract to the temporary folder and the program will run. To the user, it will behave exactly like a normal exe file.
According to the Python docs, the only program that will package Python3 as an .exe in cx_freeze, and the cx_freeze developer has explicitly stated that he will not support single-file executables (due to the 'dirty hacks' needed, which some anti-malware programs flag as malware).
Comment on the feature request to add Python3 support to py2exe.
You can compare py2exe folder structure with new python3, and make similar. Then you could use SFX idea to store these folders like libraries, python script and interpreter and set script for SFX to just launch your application. As I remember, this is possible in WinRar, and as I think now, in other archivers.

Bundle additional executables with py2exe

I have a python script that calls out to two Sysinternals tools (sigcheck and accesschk). Is there a way I can bundle these executables into a py2exe so that subprocess.Popen can see it when it runs?
Full explanation: My script is made to execute over a network share (S:\share\my_script.exe) and it makes hundreds of calls to sigcheck and accesscheck. If sigcheck and accesschk also reside on the server, they seem to get transferred to the host, called once, transferred the the host again, called a second time, on and on until the almost 400-500 calls are complete.
I can probably fall back to copying these two executables to the host (C:) and then deleting them when I'm done... how would you solve this problem?
I could be wrong about this, but I don't believe this is what py2exe was intended for. It's more about what you're distributing than about how you're distributing. I think what you may be looking for is the option to create a windows installer. You could probably add the executables as data files or scripts using distutils.
arggg Why can't my data_files just get bundled into the zipfile?
I've started using paver for this kind of thing. It makes it really easy to override commands or create new commands that will allow you to put some new files into the sdist.

Categories