【问题标题】:Pyinstaller exe file doesn't take any inputPyinstaller exe文件不接受任何输入
【发布时间】:2022-03-23 14:50:38
【问题描述】:

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

我已经尝试了几个选项 - 一个文件可执行文件(--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()

谢谢。

【问题讨论】:

  • 你运行一个窗口确保你声明程序是一个控制台程序,因为它似乎期待用户输入。所以不要忘记开关 --console 也从 onedir -D 选项开始。只有当您使用 onedir 选项时,您才应该继续使用 --onefile 或者在 path = input() 之前添加一个打印语句并使用:path = input("please enter the path") 以获得更好的调试。并准确告诉我们您在这些更改后在控制台上看到的内容
  • 当我输入pyinstaller --onedir --console script.py 时完全没有变化。我运行 dist\script\script.exe 文件,该文件打开 cmd 半秒,然后关闭它。我还添加了path = input("Enter the path")
  • 不要点击 exe 进行调试(除非你是一个非常快速的读者;-))打开一个 cmd 窗口并从那里调用 exe。这让您有时间阅读错误消息,然后您可以将其发布在此处
  • 哦,上面写着No module named 'numpy.random.common'
  • 通过添加import numpy.random.common import numpy.random.bounded_integers import numpy.random.entropy解决。 :) 谢谢!

标签: python numpy exe pyinstaller executable


【解决方案1】:

由于有 input() 方法,您应该在转换为 exe 文件时使用控制台选项。 GUI 将无法工作。试试下面的代码

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

【讨论】:

    猜你喜欢
    • 2014-09-10
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 2022-10-21
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多