python - Converting a VPython program into an exe - python

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.

Related

How to determine which Python compiler was used to create an executable

I have a fun predicament:
I wrote a little Python program a few years ago that needs an update. Unfortunately, I have lost the source code. I do however have the .exe that was created and is being used.
The problem is, I cannot seem to extract the .pyc files because apparently I didn't use pyinstaller or py2exe, and those are the only two compilers I can find scripts for. Does anyone know of a way to determine which compiler I used so I can reverse engineer this thing?

Distribute a standalone Python software with Julia dependencies

I have a software that is mostly written in Python and, for now, I'm using PyInstaller to bundle and distribute the software in a user-friendly way (it's part of my CI pipeline, for Linux and Windows).
However, my performance is terrible and I want to rewrite some heavy parts in Julia while keeping the front-end in Python. I can use PyJulia to do this, but it means that the user has to install Julia manually in order to use my program.
Julia does have the equivalent of PyInstaller, which is PackageCompiler.jl, but I don't know how to call something compiled with PackageCompiler.jl from the Python side.
How can I make this work, so I can bundle and distribute an executable that has Python, Julia and everything it needs to run?
A little more details
My end user is someone (chemists and pharmacists) that have no idea what programming is. They don't have Python, Julia or Docker (and they don't even want to install it).
In my current approach, the software bundled with PyInstaller consists of a single executable with everything inside it (Python and everything it needs). What I really want is to keep the same user experience, but also with Julia running on the backstage.
I'll implement several functions in the Julia side, and I want (almost) the same level of integration as I get with PyJulia.
Maybe I'll go to Rust and just use the C interface, but I really would like to use Julia.
Thank y'all for your time.
Per here: https://julialang.github.io/PackageCompiler.jl/stable/apps.html#Creating-an-app-1 you can get what is basically an executable file and then you can just follow this post: Python Script execute commands in Terminal to execute the file you create.
You could try using JuliaWin. This provides a standalone Julia runtime that works fully self-contained.
We deployed a tool using PyInstaller with the JuliaWin included as one of the datas as PyInstaller calls them. Iirc it was not PyJulia but JuliaCall+PythonCall doing the interfacing in our case.
Unfortunately the startup was ridiculous (order of minutes). This is in part due to Julia's startup time, but largely due to the generated .exe first having to unpack the JuliaWin. So we are currently investigating using PackageCompiler, possibly also switching to providing the user with 2 files instead of 1.

Is there any way to take executable binary (.exe) and somehow "compile" .wasm

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!

Creating an actual, executable program from Python code

I very recently wrote a program for a friend where it simplifies some important daily calculations for him/her. Now, the problem I am having is that I want to compile the code into an executable program so that he/she can comfortably run it on their machine, perhaps with a simple graphical interface or whatnot.
I have tried using cx_Freeze with Python 3.3.0 64 bit but to no avail (the program simply refuses to start on their machine; I even tried generating an executable via 32-bit Python, but also to no avail). What I then thought was that I could perhaps generate an executable program via PyGame? But the fact of the matter is that I have never used any Python-related program except the IDLE, so I am not sure what to do and look for.
Another option would perhaps be to convert the Python 3.3.0 code to Python 2.x, but the problem is that I am not familiar with Python 2.x and neither is there any automated converter available (as far as I know). I was wondering whether anyone of you could direct me to any good sources/links, since those I have been ferociously Googling are rather inconcrete.
You could just use py2exe. It is compatible with python 3. I have seen tutorials for it on youtube.
You could try embedding it in a C program, and compiling that for your executable. A decent tutorial is in the python docs at http://docs.python.org/2/extending/embedding.html
PyInstaller "is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, Solaris and AIX" and gives you one standalone executable file.
Even as a noob Python user I have succeeded to pack my app using PyInstaller (relatively) easily.

How to run a Python script in something other than cmd?

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.

Categories

Resources