首页 > 解决方案 > .exe python 应用程序不能在没有安装 python 的其他机器上运行

问题描述

我开发了一个 python 程序并使用以下方法将其转换为.exe文件:

pyinstaller --onefile master.py

之后,我将其压缩为 Zip 文件并使用NSIS为该程序制作了安装程序。然后,我将其上传到我的 Google Drive。

我切换到一台新计算机(上面没有 python)并从 Drive 下载了我的程序。我将它安装在机器上并尝试运行它。它起作用了,因为我能够输入一些东西。这个程序还不是基于 GUI 的,它要求用户在Command Prompt上输入一些东西。一旦用户在输入输入后按下回车,程序就会给我一个错误,例如:ImportError: No module named selenium

import os, time
import threading

status = True
while status:
# number of windows user want
num_of_win = input("How many screen would you like to open?\nNumber of screens [1-10]: ")
try:
    # convert it into an int
    num_of_win = int(num_of_win)
    # if number of windows is greater than 10
    if num_of_win > 10:
        print("Max number of screens you can have is 10. Please try again.")
    # if number of windows is equal to or less than 10
    elif num_of_win <= 10:
        # brake the loop
        status = False
        # open cmd windows num_of_win times
        for x in range(num_of_win):
            # this is path to index.py with parameter
            # its parameter is based on how many window we open in this for loop
            # /k = cmd stays after terminated
            # /c = cmd quits program completely
            path = "start cmd.exe /K python index.py " + str(x)
            threading.Thread(target=(os.system(path)))
            time.sleep(5)
    else:
        print("Something is wrong, try again!")
# if user enters letters
except ValueError:
    print("Please ONLY enter numbers")

我猜当我将它转换为.exe文件时,它没有加载依赖模块。我的问题是,如何让它在没有安装 python 的机器上运行?

注意:master.exe运行另一个 python 文件index.py

难道是当我将master.py转换为.exe时,它​​只加载写在master.py中的依赖项而忽略index.py依赖项????

标签: pythonpyinstallerdependency-management

解决方案


推荐阅读