ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
13.24k stars 2.34k forks source link

problem in using without console on windows, AttributeError: 'NoneType' object has no attribute 'flush' #1819

Open AbhishekSRaut opened 9 months ago

AbhishekSRaut commented 9 months ago

I am using python 3.11.5 (windows 11) When i am trying to running my script without console, which is downloading data through yfinance, it is not working. when i am running with console, then only script is proper functioning. following is error:

Traceback (most recent call last):
  File "E:\share market\yahu finance\instent running\automated_analysis\5_EMA\second_approach\run_ema.pyw", line 96, in third
    data = yf.download(tickers=f'{company}', period='60d', interval='5m', group_by='ticker', auto_adjust=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\abhishek\AppData\Roaming\Python\Python311\site-packages\yfinance\utils.py", line 103, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\abhishek\AppData\Roaming\Python\Python311\site-packages\yfinance\multi.py", line 177, in download
    shared._PROGRESS_BAR.completed()
  File "C:\Users\abhishek\AppData\Roaming\Python\Python311\site-packages\yfinance\utils.py", line 862, in completed
    _sys.stderr.flush()
    ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'flush'

any solution?

chobit19968535 commented 6 months ago

same issue, python 3.9

chobit19968535 commented 6 months ago

I have a solution y can try it,

" use .history() instead of .download() " code here:

def yfinance():
    import datetime
    from dateutil.relativedelta import relativedelta
    import yfinance as yf
    date = datetime.datetime.now().date()

    end_date = date
    start_date = date + relativedelta(months= -63)

    msft = yf.Ticker("MSFT")

    # get historical market data
    hist = msft.history(start=start_date, end=end_date, interval="1mo")
    hist.to_excel("ms.xlsx", index=None)

yfinance()

the detail ref url here https://pypi.org/project/yfinance/

god bless y