.py to exe without other files - python

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.

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/.

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

How to run pyinstaller from python script already converted to exe?

I'm trying to run pyinstaller in python exe file in order to someone without python can use pyinstaller but no idea how to do it.
I tried import PyInstaller with other needed modules and convert this script to exe but I got error "The 'PyInstaller' distribution was not found and is required by the application". I also tried to pack PyInstaller exe file but didn't worked too. Python 3.6.5
Any ideas how to do it?
Unfortunately, what you're describing is not possible with PyInstaller. I submitted an issue on GitHub, and this is what one of the developers said:
Nope, this won't work.
PyInstaller internally uses a lot of sub-processes where it is assumed that sys.executable points to a python interpreter (e.g., here); this is not true in a frozen application, where it points to the frozen executable, which ends up in effectively endless recursion.
Even if this was not a problem, the frozen application includes only a subset of python environment, so it cannot be used to freeze an arbitrary script (not to mention the issue of 3rd party packages).
So whatever use case you have for this, it cannot be supported by PyInstaller.
check the requirements for the Pyinstaller from this link initially
https://pythonhosted.org/PyInstaller/requirements.html
Then install Pyinstaller by,
pip install pyinstaller
To create .exe file use this command for basically,
pyinstaller your_script.py
To run the created .exe
METHOD 1
Do double click the .exe file in your directory.
METHOD 2
In your cmd prompt load in to your current directory or project directory then do
: .\dist\your_script.exe
because the create .exe files are saved in dist folder inside to the project folder with the name of your script file names only.

Pick up directory with pyinstaller

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

How to convert Python project into executable

I have a Python project that I want to convert into an executable. I have installed Pyinstaller. I only know how to convert one single script into .exe, but I have multiple packages with multiple python scripts.
The command line I used with success is:
pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py
pyinstaller manages relatively well the multiple '.py' files that you import, no need to cite them. Under the 'add-data' option, you list the non-py files and in my example, the 'cprofiles_lmfit.py' file is the one containing the main.
But as indicated here need help to compile python with pyinstaller (and in few other posts), I am a beginner with pyinstaller. I was never able to use the 'theano' module and I did not optimize. I still have to test the suggestions in the answer.
Converting the main script into .exe should solve the problem, use -onefile to convert it to one exe and rest of the .py files should be included.
1) Open the command prompt
2) Install pyinstaller
Pip install pyinstaller
3) Test your python script first just to check python script should work with normal
.py extension. Saurabh is the name of python file
python saurabh.py
4) Convert the python into executable file
pyinstaller --onefile Saurabh.py
Notice we have passed “–onefile” as a argument which tell pyinstaller to create only one file
5) Go to directory and navigate to the dist folder.
Prerequisite : Install PyQt5 to avoid error.
pip install PyQt5

Categories

Resources