ranaroussi / yfinance

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

Getting Import Error - Suggestions not working #1862

Open behanse opened 9 months ago

behanse commented 9 months ago

Describe bug

When importing yfinance as yf in python, I keep getting ImportError: cannot import name 'JSONDecodeError' from 'requests.compat'

Simple code that reproduces your problem

yfinance as yf

Debug log

ImportError Traceback (most recent call last) Cell In[20], line 1 ----> 1 import yfinance as yf

File ~\AppData\Local\anaconda3\Lib\site-packages\yfinance__init__.py:23 1 #!/usr/bin/env python 2 # -- coding: utf-8 -- 3 # (...) 19 # limitations under the License. 20 # 22 from . import version ---> 23 from .ticker import Ticker 24 from .tickers import Tickers 25 from .multi import download

File ~\AppData\Local\anaconda3\Lib\site-packages\yfinance\ticker.py:29 25 import pandas as _pd 27 from collections import namedtuple as _namedtuple ---> 29 from .base import TickerBase 32 class Ticker(TickerBase): 33 def init(self, ticker, session=None):

File ~\AppData\Local\anaconda3\Lib\site-packages\yfinance\base.py:36 32 import pandas as pd 34 from .data import TickerData ---> 36 from urllib.parse import quote as urlencode 38 from . import utils 40 from . import shared

File ~\AppData\Local\anaconda3\Lib\site-packages\requests__init.py:45 43 title = 'requests' 44 version = '2.13.0' ---> 45 build = 0x021300 46 author = 'Kenneth Reitz' 47 license__ = 'Apache 2.0'

File ~\AppData\Local\anaconda3\Lib\site-packages\requests\exceptions.py:9 1 """ 2 requests.exceptions 3 ~~~~~~~ 4 5 This module contains the set of Requests' exceptions. 6 """ 7 from urllib3.exceptions import HTTPError as BaseHTTPError ----> 9 from .compat import JSONDecodeError as CompatJSONDecodeError 12 class RequestException(IOError): 13 """There was an ambiguous exception that occurred while handling your 14 request. 15 """

ImportError: cannot import name 'JSONDecodeError' from 'requests.compat' (C:\Users\User\AppData\Local\anaconda3\Lib\site-packages\requests\compat.py)

Bad data proof

No response

yfinance version

0.2.36

Python version

6.5.4

Operating system

Windows 10

elliotwutingfeng commented 9 months ago

You appear to be using an old version of requests (2.13.0), could you try updating your Python environment libraries to match those in https://github.com/ranaroussi/yfinance/blob/main/requirements.txt?