Pyinstaller exe file doesn't take any input
Asked Answered
M

3

5

I want to create .exe file from .py. If I run .py file it works well and I have no problem with it. But when I run .exe file created by pyinstaller I can not input(type) anything in command line.

I have tried a several options already - onefile execuatable(--onefile), disable upx(--noupx). Both give no improvements at all.

Is it a problem that I importing my own libs? Better to paste functions I use inside my .py file?

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()

Thank You.

Masuria answered 23/10, 2019 at 13:9 Comment(5)
you run one windows make sure you declare the program to be a console program as it seems to expect userinput. So don't forget the switch --console Also start with the onedir -D option. Only if you get it work with the onedir option you should continue with the --onefile perhaps add a print statement before path = input() and use perhaps: path = input("please enter the path") for better debugging. And tell us exactly what you see on your consoel after these changesWickiup
No changes at all when I type pyinstaller --onedir --console script.py. I run dist\script\script.exe file which opens cmd for half of second and then close it. I also added path = input("Enter the path").Masuria
don't click on the exe for debugging (except you are a very fast reader ;-) ) open a cmd window and call the exe from there. This gives you time to read the error message, which you can then post hereWickiup
Oh, it says No module named 'numpy.random.common'Masuria
Solved by adding import numpy.random.common import numpy.random.bounded_integers import numpy.random.entropy. :) Thanks!Masuria
P
6

Since there is input() method you should use the console option when converting to exe file. GUI will not work. try the code below

pyinstaller --noconfirm --onefile --console test_Script.py 
Petcock answered 23/3, 2022 at 6:50 Comment(1)
It worked perfectly fine for me. Is there a way to add the file name with spaces like 'test 001.py'Neotype
T
0

My recommendation is to use pyinstaller to make exe and whenever you need input in your program, just use tkinter.

Example:

import tkinter as tk from tkinter import simpledialog for features in FeatureList:

ROOT = tk.Tk()

ROOT.withdraw()
# the input dialog
USER_INP = simpledialog.askstring(title="User Input",
                                  prompt="Do You want to Continue")
# check it out
print("Continuing", USER_INP)

Now you can use USER_INP in whatever fasion you want

Theis answered 20/3, 2023 at 6:41 Comment(0)
H
0

I found that if you just don't disable the command prompt it works fine

Helton answered 4/11 at 18:17 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Zlatoust

© 2022 - 2024 — McMap. All rights reserved.