亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

pandas_datareader,導入錯誤:無法導入名稱“urlencode”

pandas_datareader,導入錯誤:無法導入名稱“urlencode”

慕虎7371278 2023-08-08 14:52:31
我使用 pandas_datareader 工作得很好,然后今天我從下面的鏈接安裝了雅虎財經,試圖解決另一個問題。未獲取數據 Web.DataReader Pandapip install yfinancepip install fix_yahoo_finance上述安裝完成后,pandas_datareader就不能再使用了。我用谷歌搜索了它,并添加了以下導入,但 pandas_datareader 仍然無法工作。from urllib.parse import urlencode這是錯誤:非常感謝您的幫助。from pandas_datareader import data? File "C:\Users\yongn\Anaconda3\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>? ? from .data import (? File "C:\Users\yongn\Anaconda3\lib\site-packages\pandas_datareader\data.py", line 11, in <module>? ? from pandas_datareader.av.forex import AVForexReader? File "C:\Users\yongn\Anaconda3\lib\site-packages\pandas_datareader\av\__init__.py", line 6, in <module>? ? from pandas_datareader.base import _BaseReader? File "C:\Users\yongn\Anaconda3\lib\site-packages\pandas_datareader\base.py", line 7, in <module>? ? from pandas.io.common import urlencodeImportError: cannot import name 'urlencode''''
查看完整描述

4 回答

?
紫衣仙女

TA貢獻1839條經驗 獲得超15個贊

好的,我通過升級 pandas datareader 解決了這個問題


pip install pandas-datareader --upgrade

``


Thanks


查看完整回答
反對 回復 2023-08-08
?
青春有我

TA貢獻1784條經驗 獲得超8個贊

我遇到了完全相同的錯誤。我正在使用 python anaconda 2020_07 版本。

解決方案是使用 anaconda 包中最新的 pandas-datareader v0.9。如果您使用 conda-forge 中的 pandas-datareader 包(使用舊版本 v0.81),您將遇到該錯誤。這是截至 2020 年 12 月 20 日的狀態。

我運行下面的命令來安裝最新的pandas-datareader軟件包。

conda install -c anaconda pandas-datareader

錯誤消息消失,問題已得到解決。

編輯:如果 conda 稍后降級pandas-datareader回 conda-forge 舊版本,則有修復。

查看完整回答
反對 回復 2023-08-08
?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

原因是 pandas 從他們的庫中刪除了 urlencode。因此,對于較新版本的 pandas 來說,這永遠不會起作用。安裝其他庫或升級無法解決該問題。

修復方法是使用 Python3 版本的 urlencode。幸運的是,Python3 的替代品似乎有所下降:

替換這個:

from?pandas.io.common?import?urlencode

和:

from?urllib.parse?import?urlencode

并像往常一樣使用 urlencode


查看完整回答
反對 回復 2023-08-08
?
眼眸繁星

TA貢獻1873條經驗 獲得超9個贊

上面的答案是正確的。我剛剛編寫了一些實現它的代碼:


import os


basePath = os.path.join(os.path.dirname(os.__file__),'site-packages','pandas_datareader','base.py')


# read base.py

with open(basePath, 'r') as f:

    lines = f.read()


find = 'from pandas.io.common import urlencode'


replace = """from urllib.parse import urlencode"""


# add new text

lines = lines.replace(find,replace)


# overwrite old 'basedatatypes.py'

with open(basePath, 'w') as f:   

    f.write(lines)


initPath = os.path.join(os.path.dirname(os.__file__),'site-packages','pandas_datareader','iex','__init__.py')

# read iex/__init__.py

with open(initPath, 'r') as f:

    lines = f.read()


# add new text

lines = lines.replace(find,replace)


# overwrite old 'basedatatypes.py'

with open(initPath, 'w') as f:   

    f.write(lines)


查看完整回答
反對 回復 2023-08-08
  • 4 回答
  • 0 關注
  • 337 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號