【问题标题】:Why converting a .py file to a .exe file with an already converted executable file doesn't work?为什么将 .py 文件转换为 .exe 文件以及已转换的可执行文件不起作用?
【发布时间】:2022-08-17 00:02:25
【问题描述】:

我有我的convert.py 文件,可以将myFile.py 转换为myFile.exe,并且可以正常工作。但是当我将convert.py 转换为convert.exe 时,它不会再转换myFile.py

所有这些文件都在一个文件夹中:

convert.py:

import PyInstaller.__main__
PyInstaller.__main__.run([os.path.abspath(\"myFile.py\"), \'--noconfirm\', \'--onefile\', \'--console\', f\'--icon={os.path.abspath(\"icon.ico\")}\', \"--name\", \"myFile\"])

myFile.py:

print(\"Hello World!\")
while True:
    continue

运行convert.exe 时,应创建2 个文件夹:builddistmyFile.exe 应在dist 内创建,但here\'s a video of what\'s happeninghere\'s a video of what should be happening

  • 在已经打开的命令提示符下运行 convert.exe 并发布输出。

标签: python pyinstaller exe executable


【解决方案1】:

它可能正在工作,但它正在创建与运行时临时目录相邻的 dist 文件夹。尝试使用--distpath 命令行参数设置dist 目录的路径。

例如:

import os
import PyInstaller.__main__

myfile = os.path.abspath("myFile.py")
parent = os.path.dirname(myfile)
icon = os.path.abspath("icon.ico")

PyInstaller.__main__.run([myfile, '--noconfirm', '--onefile', '--console', f'--icon={icon}', "--name", "myFile", f'--distpath={parent}'])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-09
    • 2021-10-03
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多