Python Forum
How to keep a loop containing a web import working in python executable?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to keep a loop containing a web import working in python executable?
#1
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()
Reply
#2
class not properly indented
don't use system call for Loop.py, import module instead
Reply
#3
(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.
Reply
#4
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  while loop not working-I am using sublime text editor mma_python 4 1,060 Feb-05-2023, 06:26 PM
Last Post: deanhystad
  Pathlib import not working chriswrcg 9 3,519 May-29-2022, 07:37 PM
Last Post: snippsat
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,273 May-24-2022, 07:02 AM
Last Post: netanelst
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,434 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Python executable Script (Wrapper) Hwang 2 1,845 Jan-12-2022, 06:53 PM
Last Post: Hwang
  No module named '_cffi_backend' error with executable not with python script stephanh 2 5,555 Nov-25-2021, 06:52 AM
Last Post: stephanh
  Python 3.7, Windows 10, pyinstaller, winsound, no sound in executable kmarien 3 3,588 Nov-30-2020, 04:10 PM
Last Post: buran
  Make a Python program executable in Windows Pedroski55 1 2,066 Sep-26-2020, 12:34 AM
Last Post: bowlofred
  Why is the while loop not working? mcoliver88 5 3,044 Aug-18-2020, 03:27 PM
Last Post: deanhystad
  Infinite loop not working pmp2 2 1,608 Aug-18-2020, 12:27 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020