I installed “pyinstaller”, and converted a .py file into .exe, and now, when I open the .exe file, it is opened, but when I write a word in front of the input option and press Enter, the cmd page shuts down immediately.
Also, when I try to open “pip.exe” in the scripts folder of python, it is opened for seconds, but before its content appears, it shuts down instantly.
The code is a short one and it works in the editor properly and there is no problem in the code.
Also, if we suppose the problem is due to the code failure, why does the default scripts of python (pip.exe, pip2.exe in the scripts folder of python) are shut down less than a few seconds after I open them?
This the code I converted into an excitable file ( of course, I myself added if and else to the code):
input('your table:')
if table:
table = {'Sally': 4127, 'James': 4098, 'Wagner': 7678}
for name, phone in table.items():
print(f'{name:10} ==> {phone:10d}')
else:
print('the input is wrong')
These and console aka terminal programs,
You cannot double click them.
You need to start cmd.exe and then type path to your .exe at the command prompt.
Oh, you deleted " if " function that is conditional!
There is a probability that it doesn’t work?
The original code that I got from python.org tutorial is this code:
table = {'Sally': 4127, 'James': 4098, 'Wagner': 7678}
for name, phone in table.items():
print(f'{name:10} ==> {phone:10d}')
Second, my request is not about the code itself. As I explained before, it is correct.
my problem is that the converted executable file (.exe) is closed unwanted.
The point to my questions, is that if the code (the Python script) throws some error, then it would explain why the .exe simply closes.
If you are sure that the script is bullet proof and can’t, under any condition, throw an exception, then fine, that’s not the issue and my guess was wrong.
When I want to convert a .py file into .exe with “pyinstaller” the .py file should be presented in “system32” folder, also the output file is saved in the " C:\Windows\System32\dist" path instead of C:\Users\Administrator\AppData\Local\Programs\Python\Python310\Scripts
What is the solution to change the path and specify a folder other than a folder in “system32”, whether in the python path or elsewhere ?
For me it looks like you are not paying attention to some things which probably seem to be unimportant to you but they are very important in a program code.
For example here pay attention to the else: statement. It should probably follow a different statement than the for: block. Unfortunately (? ) else: after a loop block is a valid syntax but it is an advanced and not very often used construct:
The following code is invalid. You cannot start a program with indentation:
It could be helpful if you link to the actual tutorial instead of the whole python.org.
The traceback you have shown (please paste it as text - also between triple backticks - next time) comes from a different code. Please always show the code and the traceback which belong together otherwise it is useless.
On Windows (and other systems) do not put your programs into system directories and do not run them as Administrator. This way you have a high chance of wrecking your system. pyinstaller probably uses the current working directory which could make you thinking that you have to use the system directory.
You should create a project directory in your home and work there.
The issue is that I don’t know how to change the default directory of pyinstaller into another one that is out of the system files directory. May you tell me what I should do?
I use Python on machines where it is pre-installed (like on many Linux distributions) or I install it there (like on Windows). So I do not need a self-contained executable.