I am new at programming. I wrote a small program in python and converted it to .exe file with pyinstaller
. Now when i try to open the .exe file a black screen appears and closes immediately. I was able to get a screenshot:
I saw a solution like adding input()
at the end of the code but it didn't work either. My code:
import random
print("Hello, what is your name?")
name = str(input())
print("Well, " + name + ", I think of a number between 1 and 1000. Can you guess this number in 10 chances?")
number = random.randint(1, 1001)
for guessTaken in range(1, 11):
print("Take a guess")
guess = int(input())
if guess > number:
print("The number you think is too high")
elif guess < number:
print("The number you think is too low")
else:
break
if guess == number:
print("OK, " + name + ", you guessed the number in " + str(guessTaken) + " guesses")
else:
print("Unfortunatelly, you couldn't find the number. The number is " + str(number))
This worked for me:
Had the same issue but then realized that I was inadvertently trying to execute the file in the
build
folder instead of thedist
folder.Looks like you might be making the same mistake from your traceback so see if using the executable in
dist
doesn't fix it for you
(Source: https://stackoverflow.com/a/54119819/4607733)
The problem seen in the screenshot is that the Python Library cannot be found. So some configuration in your pyinstaller is wrong. Are you sure that python36.dll is in that folder? Check where your python36.dll is located (normally in the same folder where your python installation is located and your python.exe can be found). Maybe you need to add this path to your Windows Path Configuration?
Please check the following two answers to see if your pyinstaller is configured correctly:
PyInstaller not working on simple HelloWorld Program
Error loading python27.dll error for pyinstaller
The situation should be similar for you with Python 3.6
It's because you have created the exe file that depends on the entire folder. That's why it is working only in the dist folder.
Simple Solution:
Create the exe file using pyinstaller with onefile option. It will only creates the exe file in the dist folder and can execute anywhere we want.
use the bellow command in cmd.
pyinstaller --onefile file_name.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With