File resources in Python - python

I got few images and one exe file which I would like to bundle inside of the python exe file?
I mean the same or similar way that it could be done in the visual studio:
Please tell me if its possible, if so , how could I access the resources then?
I am using pyinstaller if it does matter.

You can't bundle your resources inside .Net runtime. Visual Studio allows you to bundle your resources inside your project exe not inside .net executable.
Same way you cannot bundle resources like images and exe files inside python.exe but using Pyinstaller you can create your project exe which will include your resources.
To create a single file use --onefile flag while bundling your project. As per Pyinstaller documentation -
"In a --onefile distribution, data files are bundled within the executable and then at runtime extracted into the work directory."
Here is a link for how onefile mode works

Related

How to create exe of project who has .cxx .py file and many dlls

I have a code who is depended on Qt, PyQt, VTK, ITK, libs.
using CMAKE to build
Environment : Windows
I want to distribute EXE who has cxx, py files and related dlls
I have tried to compile and got executable but my python files are remaining necked.
I don't want to share python files as a script.
how we can make those python files as a dlls
python is often a hard language to turn to exe but the best way to do so is using the pyinstaller package. Installed by pip install pyinstaller and can turn a .py file to a .exe by pyinstaller --onefile FILENAME.py in CMD. After that your exe file should be stored in a folder called disk. The other files can just be included in the same file as the exe.
docs: https://pyinstaller.org/en/stable/

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.

Making pyinstaller --onefile install portable

I'm trying to package a cli application using pyinstaller (currently for macos). My initial impression on reading the pyinstaller documentation is that I would be able to bundle all necessary files into a single file when the --onefile option is used.
However, when I bundled the file with the following command and tested it on someone else's pc, the resulting binary had a dependency to a path on my PC (specific to the bundled venv configuration). (Locally the bundled onefile binary runs fine... I assume because the path dependency is present)
pyinstaller mycli.py
Am I miss-understanding what pyinstaller does? Or, is there something special I need to do to make the resulting bundle portable?
Using python3 btw
You can use the tool dependency walker to identify the missing files (in case of libraries: dll, pyd) that need to be bundeled with your exe.
These files need to be added to spec file, as described in the docs.

PyInstaller: Can't find .so module when exe is executed

A python script uses a .so file.
I made an exe for this python script using PyInstaller.
But when I execute the generated exe, it is unable to locate this .so file
So how to link this .so to a python code that will get converted to a .exe
Note: when running the .py program, if I set the location of .so in LD_LIBRARY_PATH, it executes the program correctly but once I make the exe using
pyinstaller script.py --onefile
(with .so in the same directory), it doesnt find the .so file..
Thank you in advance
You need to make sure that your . so file is in your system library path as well as your python library path. Setting your LD path is a quick fix. PyInstaller will need it in your system path. Depending on your Windows version it's Environment variables>PATH.

python GUI to EXE with image and modules

I have created a Python GUI and trying to convert it to .exe with py2exe.
i am using following modules wx,matplotlib,numpy,time,serial,random and a .ico image as logo.
i tried create a setup.py file but it didn't work.need help creating setup file to generate .exe of my GUI.
It would be convenient if you could provide some details regarding why the .EXE is not being created. If you can't provide the details then please go through these questions on Stackoverflow, they maybe helpful:
How to build a python package into an exe
Making a standalone .exe file of a python script
Compiling python code into a single exe
Convert Python Script to .exe that will work on all/most versions of Windows
The best thing is to first refer to the official documentation!

Categories