I am trying to add one executable (.exe) file, a .conf file and a .bat file into the binary package created by pyinstaller and then through that binary package i want to call the .bat file that will send some commands to .exe and that exe will pick the configuration file from .conf and do its work.
** Example **
Click on Run button from Python Package.
Python Package runs .bat file inside it.
.bat file calls .exe with arguments
.exe picks config from .conf file and do its work
Before you create the binary through pyinstaller:
Add files (.conf and .bat and .exe) to the bundle using the Analysis call in the .spec file.
When you run the binary created through pyinstaller it unpacks itself at a temporary location in AppData on Windows by default. You should be able to get that path through sys._MEIPASS
In the python script run the .conf, .bat and .exe files preferably using subprocess.
Related
Let's say I have an application with a .py file extension and I want to use PyInstaller to create it into a standalone executable with a .exe file extension. However I only want one .exe file that does not require dists nor a workpath.
Is it possible to use PyInstaller to create a standalone file that does not need a distpath nor workpath to function correctly?
I think the --onefile option is what you are looking for? This has worked fine for me in the past in order to create a single .exe file.
I am getting a error in converting a .py file to .exe file. The exe file shall be delivered at the build folder but it was not there.
In the explorer, go to the .py file you want to convert to an .exe
Click the path and write cmd
In the terminal that should have popped up, type pyinstaller --onefile (and -w if your program doesn't require the terminal) filename.py
Hit enter and wait for it to convert
The .exe now should be in the dist folder, which is in the same folder your .py file is in
Good luck! :)
Currently to use Pyinstaller I open a Python command console then go to the location of my .spec file using cd and type pyinstaller Software.spec. It works well but I'd like to automate that and have a .bat file do those operations for me.
I have made small .bat files to execute my programs (see below) and I thought the structure for calling Pyinstaller would be close but I'm groping.
C:\Python\python-3.6.3.amd64\python Software.py
pause
Failed attempts of .bat files to run Pyinstaller include:
C:\Python\python-3.6.3.amd64\python\Scripts\pyinstaller.exe Software.spec
C:\Python\python-3.6.3.amd64\python CALL :pyinstaller Software.spec
Any idea would be welcome.
Solution
We need to execute Pyinstaller.exe with Python like so:
"path\to\python.exe" "path\to\pyinstaller.exe" "path\to\my\Software.spec"
Typically you need to call the path to the script as well, but also always double quote paths to ensure you do not get some whitespace kreeping in. Always call the full extension name of an executable as good measure.
"C:\Python\python-3.6.3.amd64\python.exe" "C:\path\to\Software.py"
You can also start it, but in the same batch window:
start /b "" "C:\Python\python-3.6.3.amd64\python.exe" "C:\path\to\Software.py"
or with pyinstaller.exe example:
"C:\Python\python-3.6.3.amd64\python\Scripts\pyinstaller.exe" "C:\path\to\Software.spec"
A simple drag and drop of any python file will result in a compiled exe file in the dist folder created from executing the pyinstaller script.
#echo off
PATH = "%PATH% + %USERPROFILE%\AppData\local\programs\python\Python38"
:: %1 is the file dropped on the batch file
pyInstaller --windowed --onefile %1
If you change %1 to the filename it will also work. Save the script as Pyinst.bat then drag and drop a python file onto it.
I wrote a program in Python that includes external files, including images and a GUI .ui file.
I want to convert the Python script to a single executable (.exe) file using PyInstaller. When I try to open the .exe file, the program does not open.
You will need more information on why the application is closing immediately in order to solve your problem. To view the error messages associated with running your executable, run the .exe file from the command prompt: /path/to/app/dist/MyApp.exe. This will allow you to observe any errors that may exist after the app was bundled. If the program fails during an import statement, you may need to add a package to the hiddenimports list in the .spec file. Check the PyInstaller documentation for instructions on modifying the .spec file.
I have a Python script that takes the directory path of a text file and converts it into an excel file. Currently I have it running as a console application (compiled with py2exe) and prompts the user for the directory path through raw_input().
How do i make it such that I can drag & drop my text file directly into the .exe of the python script?
The dropped file will be available as an element of sys.argv.