我正在尝试运行从.py转换为exe的程序,但出现错误“无法执行脚本'文件名'”。

时间:2020-08-24 19:14:40

标签: python exe pyinstaller

我编写的脚本非常简单,不需要任何外部文件即可运行。在将其转换为可执行文件之前,我也对其进行了测试,并按预期运行。 Pyinstaller是我转换它的方式。

这是代码

# Imports
from shutdown import *

def initiate_shutdown():
    """Activate the program by using this singular function"""

    # Main code
    shutdown(force=True, warning_off=False)

# Exectutes it
initiate_shutdown()

1 个答案:

答案 0 :(得分:0)

尝试将其更改为:

# Executes it    
if __name__ == '__main__':
    initiate_shutdown()