Reputation: 43
I have a python file that is simple and opens up webpages from a text file. It is supposed to work and even works in visual studios. I decided to turn it into a exe file using pyinstaller. It outputted a exe file just fine and I opened it but it did nothing and closed right after I opened it.
I used Python 3 and downloaded the pyinstaller inside of Anaconda. Thank you
My code:
import webbrowser
print('Welcome to my project')
webfile = open('webfile.txt', 'r')
for lines in webfile:
webbrowser.open(lines)
k = input('Press Enter to Exit')
Upvotes: 3
Views: 1449
Reputation: 717
Most of the times, when it comes to reading a file via the pyinstaller bundeled executable, you do not have the right path to the file. Here are some ways you can get around it:
webfile = open('<full_path_to webfile.txt>', 'r')
if
condition to set the path of the expected file. There are many answers (here, here) on SO which will explain this in further detail. PS: It is not a good practice to read the file without a context manager. This will explain why.
Upvotes: 1