Reputation: 21
After stumbling through the dark for several days on a python script, I finally have a finished product that I want to deploy to the rest of the machines in the office. Portions of the script are posted below. The script works as intended when run from the IDE, but when I use PyInstaller to create a standalone .exe file, it no longer runs correctly. I have been working with exception handlers to narrow down where the error is coming from and I finally found the portion of code that causes the .exe to stop and close.
One_String = easygui.enterbox('list the fund and etf tickers here, space delimeted')
try:
list_o_tickers = One_String.split()
finally:
pass
The purpose of this code is to get a list of tickers as input from the user, which will then be the input for the following code
for i in list_o_tickers:
AAB = i
AAC = 'http://morningstar.com/funds/xnas/' + AAB + '/portfolio'
re = req.get(AAC)
if re.status_code == 200:
URLlist.append(AAC)
else:
AAC = 'http://morningstar.com/etfs/arcx/' + AAB + '/portfolio'
re = req.get(AAC)
if re.status_code == 200:
URLlist.append(AAC)
else:
pass
The variable URLlist will then be iterated over by a web scraping class, which scrapes for the desired data and works with it to create a pandas data frame(Total_of_Totals). The script then prompts the user for a file path to export the data to.
outputpath = easygui.enterbox('coppy and past the filepath for the destination folder here')
time = datetime.now()
strtime = time.strftime("%H-%M-%S")
notrawstr = outputpath + '\DataTransfer' + strtime +'.xlsx'
rawstr = r'{}'.format(notrawstr)
Total_of_Totals.to_excel(rawstr)
All exceptions are posted to a text file. After running the script, the file says:
Traceback (most recent call last):
File "ScraperProject1.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "pyppeteer\__init__.py", line 33, in <module>
AttributeError: 'NoneType' object has no attribute 'split'
If I had to guess, the program is continuing past the line where I instantiate the One_String variable as easygui.enterbox('list the fund and etf tickers here, space delimited) before the dialogue box even appears to the end-user. In the IDE, the program stops until the user supplies an input. However, when running from the .exe file created by pyInstaller, no entry box appears.
Please help!
Upvotes: 0
Views: 189
Reputation: 9418
From docs of easygui.enterbox()
function:
Returns: the text that the user entered, or
None
if he cancels the operation.
So you should test for None
before splitting:
responded_text = easygui.enterbox('list the fund and etf tickers here, space delimeted')
if responded_text is None:
print("Sorry, user has clicked cancel! No text entered.")
# what would you like to do if no text was entered or input canceled by user?
else:
print(f"User entered: '{responded_text}'")
try:
list_o_tickers = responded_text.split()
finally:
pass
Upvotes: 0