[英]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
. 当前要使用Pyinstaller,我打开一个Python命令控制台,然后使用
cd
转到我的.spec文件的位置,然后键入pyinstaller Software.spec
。 It works well but I'd like to automate that and have a .bat file do those operations for me. 它工作正常,但我想自动化它,并让.bat文件为我执行这些操作。
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. 我已经制作了小的.bat文件来执行我的程序(请参见下文),我认为调用Pyinstaller的结构将很接近,但是我正在摸索。
C:\Python\python-3.6.3.amd64\python Software.py
pause
Failed attempts of .bat files to run Pyinstaller include: .bat文件运行Pyinstaller的失败尝试包括:
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. 任何想法都将受到欢迎。
We need to execute Pyinstaller.exe with Python like so: 我们需要像这样用Python执行Pyinstaller.exe:
"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: 或使用pyinstaller.exe示例:
"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. 简单地拖放任何python文件都会在执行pyinstaller脚本创建的dist文件夹中生成一个已编译的exe文件。
@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. 如果将%1更改为文件名,它也将起作用。 Save the script as Pyinst.bat then drag and drop a python file onto it.
将脚本另存为Pyinst.bat,然后将python文件拖放到该脚本上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.