python - Pyinstaller exe文件不接受任何输入

标签 python numpy exe pyinstaller executable

我想从 .py 创建 .exe 文件。如果我运行 .py 文件,它运行良好,我没有问题。但是当我运行 pyinstaller 创建的 .exe 文件时,我无法在命令行中输入(键入)任何内容。

我已经尝试了几个选项 - onefile execuatable(--onefile),禁用 upx(--noupx)。两者都没有任何改进。

我导入自己的库有问题吗?最好将我使用的函数粘贴到我的 .py 文件中?

from PIL import Image
import numpy as np
from convetai.cropImage import cropImage, step
def main():
    path = input()
    img = np.array(Image.open(f"{path}"))

    print("Your image has a shape of ", img.shape)
    n = int(input("Enter number of divisions."))
    #dx, dy = step(n, img.shape)
    i = int(input("Enter num of row"))
    j = int(input("Enter num of column"))
    n_img = cropImage(img, n, i, j, save=True)
    print("Done.")

if __name__ == '__main__':
    main()

谢谢。

最佳答案

因为有 input() 方法,所以在转换为 exe 文件时应该使用控制台选项。 GUI 将不起作用。试试下面的代码

pyinstaller --noconfirm --onefile --console test_Script.py 

关于python - Pyinstaller exe文件不接受任何输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58523628/

相关文章:

python - 究竟什么是序列?

python - 使用两个掩码 a[mask1][mask2]=value 更新数组值

python - pyinstaller multipackage错误(MERGE方法)

Python JSON解码报错TypeError : can't use a string pattern on a bytes-like object

python - 向构造函数传递太多参数是否被视为反模式?

python - 在 python/PIL 中执行与 ImageMagick 的 "-level"相同的操作?

python - 从 numpy 数组中检测高值

带有 JRE 检查的 Java 应用程序的 Windows exe 启动器

c - 有什么办法可以运行 .exe 而不受到 Windows 的投诉吗?

python - Python 3 和 Python 2 之间的通信