Python Forum

Full Version: How to keep a loop containing a web import working in python executable?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I've run into an issue with my program not running properly in an executable file. Specifically, I'm using Python 3.8 for writing the script that contains a function that goes to yahoo.finance.com as is and imports data associated with tickers within a loop using an get_quote_data.

There are other functions called into play afterwards to manipulate the data with the end result being a final CSV file compiled with imported data for all tickers in loop.

When running the script in Python, it works perfectly; however, I used pyinstaller to create an executable file and the function for importing the variable's data from yahoo finance appears to freeze and shows the same data associated with the first ticker for all tickers thereafter. The final file has all tickers appended to it in rows but with the first ticker's data showing as duplicates for every row.

I have tried using multiprocessing.freeze_support() and time.sleep. I have also created the exe with --onedir as I've read it is required over --onefile when multiprocessing is involved such as a loop etc. The multiprocessing.freeze_support() at the end doesn't appear to have the correct argument as I get an error saying multiple arguments found.

I am rather new to python and programming in general and need some guidance/advice on where I should go from here to get the function moving and not stalling out as it appears to be doing. Please see below for my general script:

Main script includes this function:
    class Window2:

    def Loop(self):
        os.system('Loop.py')
Which calls os.system('Loop.py'):

    for ticker in df['Symbol']:
    #Import stock data
    results = si.get_quote_table(ticker, dict_result=False)
    results.to_csv('Stockdata.csv', index=False)
    time.sleep(5)
I end the main script as follows:
    if __name__== '__main__':
        multiprocessing.freeze_support()
        p = Process(target=Window2.Loop, args=('self'))
        p.start()
        main()
class not properly indented
don't use system call for Loop.py, import module instead
(Feb-22-2020, 05:05 PM)Larz60+ Wrote: [ -> ]class not properly indented
don't use system call for Loop.py, import module instead

Thanks, Larze60, for your reply. How do I go about doing a module import? Do I need to change the py file into a module (I apologize, but still learning). Also, do you think the args='self' is causing an issue?

Thanks again.
(Feb-22-2020, 04:27 PM)coder1384 Wrote: [ -> ]When running the script in Python, it works perfectly;
Post all of code that works when run it as a script in Python.
Read this using code tag ,as you also have been warned about this in previous posts.