Python- Compiling a .py program with .exe dependencies - python

I have written a Python (v3.8.1) Python program which relies on a c compiled .exe program. The Python script itself works as expected and I am ready to package it for use within Windows, in environments where Python is not installed.
I want to wrap both programs together under one .exe if possible and practical.
Based on a comment, I have gone through the compiling process with Pyinstaller using the following commands:
pyinstaller myprogram.py --hidden-import notional_library --add-data
compiled_c_program.exe;. --add-data dependency.COF;. -w -D
And the program works perfectly. However, when I change -D to -F to create a onefile.exe, the program breaks along the lines of the compiled c program, which is confirmed when I debug the program.
I have also tried adding the c program as a binary, but that does not work either.
Placing the dependencies in the same folder does work, and is an amenable solution, but I would still prefer to wrap both programs into a single executable if possible.

Related

How to create a onefile executable from a python script?

I have a decently complicated .py script, which uses several packages, incl matplotlib, numpy, and one custom, that is compiled from a fortran code. I want to make a windows executable out of this, that is distributeable in a way, that users don't need to have python installed on their computers for it to work.
When I make my .exe with pyinstaller --onefile myprogram.py the resulting .exe doesn't run on its own (if I doubleclick on it, the GUI it contains doesn't open), however, if I have anaconda installed, from anaconda prompt I can run it with .\path\to\program\myprogram.exe and it works all nicely (without creating an environment with matplotlib etc)
My question is: how can I make it so that the one file includes all the dependencies and I can just doubleclick on it and go?
Thanks in advance!

How to make python pyinstaller executable sharable

I have tried a lot but I cant wrap my head around it. I make a lot of tkinter GUIs that I would like to share with others, but I am not able to. I use pyinstaller to create an executable out of it and mailing the compressed folder. It still doesn't seem to work as warnings are raised.
Some of the warnings include things like 'this folder has an executable file that might not be safe.'
The executable GUI works completely fine on my computer.
pyinstaller --onefile -n GUI -i icon.ico -w main.py
How am I supposed to make an executable that is sharable?

Python/C API project - compile to exe

I'm working on project where I am using Python/C API and C++. C++ is used for most part of application, mainly for gui (wxWidgets), while Python is used for calculations on large data sets, e.g. from files. I'm doing it in Visual Studio and when I run the project in IDE everything works fine, like I want it to. Also, the exe file that is created during the launch of the project in the visual studio, when it is in the same folder with the python .py file, also works as it should be. But what I want to achieve is a complete application contained in one exe.
While searching for a solution, I found various possibilities to create an exe from a python file. For example, PyInstaller which I tested for a simple "hello world" python file and it works. However, I don't know and can't find a solution how to combine the exe created in visual with a python file.
In PyInstaller github issues I found that line:
pyinstaller App.py --add-data 'pathtoexe\your.exe;.' --add-binary "pathtodll\your.dll;." --onefile --noconsole --clean
And I typed this into the console:
pyinstaller myPythonFile.py --add-data 'myVisualGeneratedFile.exe;.' --onefile --noconsole --clean
But after that, when I clicked generated exe file, nothing happens.
I hope that someone has done a similar thing before and I can find help here because I'm already losing my mind on it.
According to https://pyinstaller.readthedocs.io/en/stable/usage.html, you should use --add-binary and not --add-data.

Pyinstaller - multiple python scripts

I have two Python scripts which produces a GUI and runs code off some of the buttons. When run from Python, I run mainImpactTool.py which then runs impactTool.py to produce the GUI.
mainImpactTool.py
impactTool.py
I followed the guidance here:
https://pythonhosted.org/PyInstaller/usage.html#what-to-bundle-where-to-search
So I could create a single executable for running on Windows.
If I had one script I would normally run:
Pyinstaller --onefile mainImpactTool.py
However, to use two scripts, I did this:
Pyinstaller --onefile mainImpactTool.py impactTool.py
Pyinstaller works, but when I run the .exe file I get the error:
ImportError ... Failed to execute script mainImpactTool
Any suggestions on what I am doing wrong?
Thank you
Pyinstaller --onefile mainImpactTool.py
Try this it will work. Pyinstaller will recurse over all your imports(impactTool.py) and include it in the .exe.

Is there a way to produce executables from python scripts using makefiles?

I have a python script "MAlice.py" (main) which depends upon several other scripts including yacc.py and lex.py and whatever they in turn import.
I don't have a lot of experience writing makefiles and I'm wondering how I can produce an executable called "compile" using this code, so that someone could call:
make
./compile "someTestFile.alice"
I'm working in Ubuntu.
I think what you are looking for is a way to package your python project into a self-contained executable. It is not a compiling process but rather just a bundling into a portable environment. This will include your python interpreter.
You can look into pyinstaller for linux or windows. And py2app for osx (pyinstaller would work on osx as well to create just a single file)
If what you are after is the ability to provide a source package to someone and for them to be able to run a build command, and have an executable entry poiny called "compile", then what you want is simply a setuptools script. This will install all the declared dependencies and will create any named entry points you define.
http://packages.python.org/an_example_pypi_project/setuptools.html
Python scripts aren't compiled; they're interpreted. You can turn MAlice.py itself into an executable script by adding this as the very first line:
#!/usr/bin/env python
And making the script executable:
chmod a+x MAlice.py
So then you can simply run it like this:
./MAlice.py "someTestFile.alice"

Categories