Guimoute
Guimoute

Reputation: 4629

How to call Pyinstaller via a .bat file?

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"

Upvotes: 1

Views: 4369

Answers (2)

Michael Mulvey
Michael Mulvey

Reputation: 131

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.

Upvotes: 0

user7818749
user7818749

Reputation:

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"

Upvotes: 1

Related Questions