Pick up directory with pyinstaller - python

I have made a small programm with Python 3 and Qt-Designer using Pyqt5.
the programm should open a pdf file which is located on a directory on my pc and another exe file, which is also on my pc.
I'm using in the code:
os.startfile("D:\Python_files\MA\Programm\K_file\dist\K_D\K_D.exe")
os.startfile("D:\Python_files\MA\Programm\Help.pdf")
then I used pyinstaller to make it standalone app. The problem is that pyinstaller does not pick up those two file (pdf and exe). So when somebodyelse download the app on thier pc, it wont work because the pdf and the exe are missing.
How to fix this?
I'm using this command in pyinstaller
pyinstaller --onefile --icon="if_icon_64682.ico" --clean ProgV_1_6_Final.py

Related

pyinstaller python file + exe in only one exe

py file in which I am executing a .exe file created in C++ (is inside a "data" folder)
Python Code:
os.system("data\\time.exe")
When I use the pyinstaller with the --onefile attribute I can't find a way for my program to compile the .py file + the "data" with another .exe inside.
Does anyone know how to convert my entire program into a single .exe? in which I can run my python program and also my .exe from C++ inside?
(I have tried to test with the .spec and with the --add-data attribute but I can't find a way that is compatible with what I want to do)
I look forward to your response,
Thanks you very much <3
There is a program called auto-py-to-exe which creates an exe out of your program without requiring you to create a setup file. The interface is great and allows you to easily create and exe without creating a setup.py. This also allows you to package your app as a single exe, without any other files. Below is a screenshot:
You can install the program by typing into the command line:
python -m pip install auto-py-to-exe
You can run it by typing in:
auto-py-to-exe
To see more about auto-py-to-exe, please visit the PyPI page at https://pypi.org/project/auto-py-to-exe/.

Executable PyQt5 desktop apps

I am creating a desktop app with PyQt5 then making it executable with the pyinstaller, but I want to create an installation so that when I share just an exe file, people can first install dependencies, then run the app. Pyinstaller creates dist and builds folders on my PC, and I want this app to create these required folders on the other computer when exe file is used; what I want to do is make the app have a set-up so that all the dependencies will be installed for others. I searched on the internet but couldn't find a way to do it.
You can use pyinstaller with following command
pyinstaller --onefile --windowed myscript.py
this will create single exe file in dist folder
see this for more info
https://pyinstaller.org/en/stable/operating-mode.html#bundling-to-one-folder
I found this, it uses InstallForge to create a setup for the app. If you have better options, it would be better to know

How to convert tkinter script which uses multiple image resources to create a single executable

I want to create a single executable from my Python project which uses tkinter. A user should be able to download and run it without needing Python installed. What can I use to build a self-contained executable from a Python project?
my question is somewhat similar to this one but I didn't find what I was looking for there.
I have a folder which looks like this:
-project/
-script.py
-res/
-image1.jpg
-image2.jpg
-image3.jpg
In my script.py I am using the images from the res folder in my tkinter UI and I want to create an executable out of this script. what would be the best way to tackle this problem?
You can try using PyInstaller
PyInstaller - How to convert to .exe
1. Installation
The pyinstaller module makes you able to create a standalone exe file for pc from a python script, so that you can use it on other computers than do not have python or your python version.
To install pyinstaller: pip install
2. Create an exe
After you installed pyinstaller, go in the folder where your python script to be transformed in exe is and type in the command line (go in the address bar on top of the window and type cmd). Then type :
pyinstaller yourscript.py
where your script is the name of your file.
You will find a folder called “dist” where there is a folder called yourscript (if the name of your script was this) where there are many files and the exe file that will allow you to run the script also on other computer. You just have to copy the whole folder.
3. What to do if there are images
If you use images, that are in the same folder, for example, you can copy manually into the folder made by pyinstaller or you can run this command to make it do it for you:
pyinstaller –add-data “*.png;.” yourscript.py
This way you will see that in the folder where your exe is there are also the png files (all of them, if you want just one do not put the asterisc, but the whole name of the file.
External links - PyInstaller
Use a bundler like Pyinstaller.
Pyinstaller website
Include images in Pyinstaller
Note: If you are having issues with tkinter and pyinstaller take a look at this: Problems with Pyinstaller with tkinter app on python 3.5

.py to exe without other files

Using pyinstaller, I created a .exe file and other files. Can I create ONLY the .exe, without other files, or is there any way to put together all files? I need your help.
Run this command;
pyinstaller --onefile your_script_name.py
If you are a learner, you will get good insight into how to create an exe file using PyInstaller. I provide below the github link for a very small project. You will be able to create exe using the following command.
setup.py clean develop install
Github Link : https://github.com/debjava/py-exe-creator1
First you download the project and run the above command just to see the exe.
As per the above project, you can similarly put all your project file and you can use the same command to run to create exe file using pyinstaller.

Pyinstaller exe single file executable on different computer

I am trying to make a gui to control a spectrum analyzer. The code works when running from the IDE. I generate an .exe unsing pyinstaller with the code.pyinstaller.exe --onefile --windowed --icon=spec.ico spectrum_analyzer_gui.py The .exe works great on the computer that generated it.
I tried to run the .exe on a different computer but got an error 'Failed to execute script spectrum_analyzer_gui'
I copied the icon to the same location.
What else do I need to do so the application runs on a different machine?
I have attached a like to a .zip in dropbox with the source code and build.
https://www.dropbox.com/s/87uqynllnlv72c4/Spectrum%20Analyzer%20Gui.zip?dl=0
Try adding a --hidden-import=tkinter to your exe generation.

Categories

Resources