I have read several posts regarding creating .exe files from Python scripts using tools like cx_freeze or pyinstaller and read a few articles which basically admit to having the same issues as the posts do - namely, the .exe files are simply too large (sometimes in the hundreds of MB). I have tried this myself on a script and simply because libraries like Numpy and Pandas were packaged into it, the executable became massive.
This is a bit of real world scenario so I am taking a shot here at asking about this but is there no way to create solutions for teams who do NOT have coding experience? The only options I can think of are:
Require all users to have Python and the related libraries installed on their systems and train them in running the scripts.
Perhaps push the script to a cloud service and run the script from there (though this may be an issue when it needs to connect to inhouse databases and other source systems).
Accept the size of the .exe file and save it on shared drives and go for a lunch break every time you need to run it.
Related
I'm working on a 2d game in pygame, and I want it to be available on the web. In my head, a fun way to challenge myself is to use web assembly to make the game available on the web. So I'm wondering if there is any way to take executable binary (.exe) and somehow "compile" .wasm if that's still sayable at this point) to
Running a .exe via WebAssembly (WASM) in the browser will be extremely slow and inefficient but is still possible with a Wasm PC emulator ( eg v86 ) + an OS ( eg ReactOS ).
But if you can gain access to game sourcecode then
what you could do is using CPython 3.11 which supports WebAssembly target ( with the help of Emscripten a C/C++ compiler targeting WASM ).
Add to that the latest development version of PyGame and minor changes to the game main loop source code.
You can now run directly the game if you pack both sourcecode and assets with the emscripten File Packager instead of a .exe you will have a .wasm (cpython) + one .data (assets+code) and some javascript glue to load them.
Please note that currently there is no straightforward tool to do that at once, but situation will most likely evolve very quickly after release of CPython 3.11.
Personally, I don't have much experience with combining .py and .wasm files, but I do know some stuff regarding running Pygame:
First of all, you can run basic Pygame files here. I scoured the internet in search of an independent Pygame running engine, and this is the only one I could find.
Second, you can use PyInstaller to convert your Pygame file itself to .exe (it packages it nicely, but can't be signed, so some computers might think it's a virus). I have no idea how to run this specifically on the web, but if you can manage to find a web platform that can run it with a window, then you can maybe try and run that .exe with Javascript and connect the .wasm to that.
Third, I'm not sure there's a way to run .exe files with a separate window in web assembly, but I'm not too familiar with wasm.
I hope that helped!
Apologies for the extremely vague question, but I've been wrecking my head trying to reduce the size of an Pyinstaller .exe and I decided to check what more experienced Python developers think about the general file size of such files. I'm working alone so I really don't know who else to ask.
My script needs quite a lot of modules, including APscheduler (including SQLAlchemy), sqlite3, tkinter, datetime, patool, shutil, but ultimately it's a relatively simple programme that should run as a Windows background service (ultimate goal). No pandas, numpy, scipy, keras or other big libraries are used. I also include 5 .png images for the GUI (around 350 kB total). This creates a 15.5 MB .exe and when running, the programme takes up 30 MB of the physical memory.
All advice online talks about using Python (not Anaconda) to create separate virtual environment for the file(I'm working on doing that now but it has been painful..). Looking at the dist folder Pyinstaller creates, most of the large .dll seem to be essential for the running of the programme (mfc140u.dll, python37.dll, tcl, tk, multiprocessing, sqlite, ..) and there doesn't seem to be pandas or tensorflow or other libraries that are otherwise installed in my conda site packages. I should also mention this is my first running programme, so I imagine the code architecture is not as efficient as it should be.
Particularly APScheduler has quite a lot of dependencies, so I am not sure isolating it to a single virtual environment would have such a huge effect on the size. However, I was told the file should be a lot smaller so it does not burden the OS - a similar but slightly simpler software created in C# is just 64 KB.
Would experienced developers say that this file size is normal given all the libraries/dependencies, and what else can be done apart from creating a separate venv in pure Python?
EDIT: After 3 days and battling a few thousand errors, I managed to make the script run in system Python (as opposed to Anaconda) with its separate virtual environment, in order to install only the packages I need. The result: the file is only about 2 MB smaller. So definitely was not worth it. But for other people it might be I guess.
15 megabytes of disk and 30 megabytes of memory isn't really much in today's terms at all. (IMHO, whoever told you it would "burden the OS" is living somewhere in Windows 95 land, or earlier still.)
That file size is normal considering the Python interpreter, standard library, additional libraries and all are bundled in; a C# program being 64 kilobytes and doing the same is benefiting from the C# libraries and virtual machine having been shipped with Windows.
For contrast, in JavaScript land, where desktop apps tend to be Electron based, you start from around a hundred megabytes of disk use...
The file size is normal. I don't think you can do much more with it.
Pyinstaller bundles python interpreter and supporting files along with it and the win32 dlls which will most probably take up atleast 12MB. You can check this by making a virtualenv with a hello world script and turn it into a exe.
As AKX says it doesn't burden the system much more than running python itself. The large file is not loaded into memory completely. It is unzipped into the %temp% folder with a folder name containing _MEIPASS and only required files are loaded into memory on the target machine. However, there is an overhead as startup to create a folder, unzip the files and delete them after exit.
Also don't compare it to C,C# etc because those languages don't need to bundle additional files like python because they would already be included in your system. Also I haven't used it myself but you may try py2exe. It is old but many apps use it and could reduce the file size a bit.
I am currently making a physics simulation using VPython, and want to turn it into an exe file, using pyinstaller, so that it can run on a Mac laptop.
Essentially, I have two questions - one short and one long.
Short question: will the exe file I create using pyinstaller run on a Mac laptop if I created it using windows?
Long question:
I converted my program into an exe, but it doesn't work. Here is a screen shot of the error:
Pyinstaller error
Good news: I think I have found a solution to my problem from another question on stackoverflow, but I am a newbie and can't comprehend a single word of the answer. And, the answer uses anaconda, but I am using pycharm... in other words I am completely lost.
Link to answer: how to make vpython .exe using pyinstaller
In order to convert a Python program into an executable file (i.e. “freeze” the program), you’ll need something like PyInstaller. PyInstaller and related projects (such as py2exe) take Python programs, and package them into *.exe files for your users to run. The end result is a standalone executable file that doesn’t require Python to be installed on the end user’s system.
Keep in mind though, that these methods of “freezing” a Python program can incur a fairly large startup penalty and/or bloat your executable size. The end result is an executable that may take a significantly longer time to start up than usual, and may be much larger than you would expect it to be.
This is my first attempt in hosting one of my Python projects and after reading multiple tutorials, I am confused on which steps are necessary (i.e. writing it into a python package, freezing it as an .exe, etc)? A lot of the tutorials seem to be overkill for what I feel should be an easy task.
Currently, I have two .py files (one for the gui and one for the back-end) and few miscellaneous data files. The program works for Python 2 and 3.
The end goal would be to have a file or package that another person would be able to download from my website that has a desktop icon executable that prompts the gui. The package will need to be able to install a list of requirements (I can do this through a requirements.txt file?).
Would anyone know what the "bare bones" structure should be? (i.e. would I need to write it as a package or would freezing it with a req instllation pre-pended to the gui file work?)
Thanks!
I have written a program. I don't know if it is important how it is written but you can find it here: http://pastebin.com/Z3ZvVPV8 Basically, it asks you to assign values to variables and will perform calculations depending on what variables you chose, and prints the answer.
I would like to know how I can make the program run in a window other than cmd (I am using Windows Vista 32bit). I don't need much at all in terms of GUI, just a window that is a bit more user friendly/easier to look at when they are using the program.
EDIT: To those suggesting using IDLE, while that would work for me, if others want to use the program they would have to download it, so I was hoping for a way for that not to happen.
Python comes with a sort of default GUI package TkInter you can use it.
Also there is a lot of other GUI packages available.
The Python standard library offers a lot of ways to implemt simple (but also rather complex) GUIs. I'd like to point you at the documentation of TK (tool kit for graphical interfaces) http://docs.python.org/library/tk.html where you will find also some useful example of use.
Py2Exe is a viable option if you really don't need a gui. This will make it run and look like a command prompt, but it will be an .exe file. Here is a quick quote from thier page: "py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation."
Another alternative is to get Portable Python. Here is a quote from thier webpage: "Portable Python is a Python® programming language preconfigured to run directly from any USB storage device, enabling you to have, at any time, a portable programming environment. Just download it, extract to your portable storage device or hard drive and in 10 minutes you are ready to create your next Python® application." After packaging the portable python and your .py or .pyc file then create a .bat file that runs the portable python "Python-Portable.exe" with the correct command line parameters for loading your script. Be sure to use relative paths in the batch file in case they are running it from a flash drive, or something other than the same location as you.
NOTE: This is really not a good way to do this as thier download page states: "Installed size: based on selected packages, between 49MB and 480MB". Also be sure to read the the current Python Software Foundation License, as that is what Portable Python is released under, and it may or may not be legal to package it in a closed source project. I haven't really looked at the license myself to be able to tell you. If you are releasing it as open source, then there would not be an issue though. As a quick side note, if you need that .bat file to be a .exe file then you can use a .bat to .exe converter battoexe.com is one. This is really going the long way about doing the whole thing, but it is an option.
Sources:
Working with Python on and off for 7 years now, a lot that using a portable version on a flash drive, and also dealing with Batch files much longer.