简体   繁体   English

如何通过.bat文件调用Pyinstaller?

[英]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. 任何想法都将受到欢迎。

Solution

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.

相关问题 通过 .bat 文件将参数传递给由“PyInstaller”转换的 .exe 文件 - Pass argument through .bat file to .exe file that converted by 'PyInstaller' Pyinstaller - 通过 .bat 文件隐藏和运行可执行文件 - Pyinstaller - Hide and Run Executable file through .bat file 通过vbscript或bat文件调用python启动新进程时获取未修改的环境变量 - Getting unmodified enviromental variables when starting new process via vbscript or bat file call to python Python:通过网络执行bat文件 - Python: Execute bat file via Network Python 脚本在 Pycharm 中运行,但不是通过 bat 文件 - Python script is running in Pycharm but not via bat file 如何通过我的规范文件说服 PyInstaller 在它制作的 EXE 中包含 libvlc.dll? - How can I convince PyInstaller, via my spec file, to include libvlc.dll in the EXE it makes? 从python调用bat文件并导入环境 - Call a bat file from python and import the environment 如何在没有额外文件的情况下使用pyinstaller - how to use pyinstaller with no extra file 如何从将运行 python 文件的命令提示符调用 bat 文件? - How do I call a bat file from command prompt which will run a python file? Python,代码有效,但通过bat文件打开会出错 - Python, code works, but openning via bat file get error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM