nflfastpy已安装但无法导入的报错问题求助
解决方案
方法1:修改nflfastpy初始化文件
报错原因是nflfastpy的__init__.py使用了matplotlib已移除的URL读取逻辑,新版本matplotlib不再支持imread()直接读取网络链接。
- 找到环境中nflfastpy的安装路径(示例路径:
C:\Users\austi\anaconda3\envs\pythonCoursera\lib\site-packages\nflfastpy\),打开__init__.py文件 - 在文件顶部添加以下导入语句:
import urllib.request from PIL import Image import numpy as np
- 定位到这行代码:
default_headshot = mpl_image.imread(headshot_url)
- 替换为:
with urllib.request.urlopen(headshot_url) as response: default_headshot = np.array(Image.open(response))
保存文件后重新执行导入操作即可。
方法2:降级matplotlib到兼容版本
若不想修改库文件,可安装仍支持imread()读取URL的matplotlib版本:
pip install matplotlib==3.6.0
安装完成后重新运行代码即可。
内容的提问来源于stack exchange,提问作者oz.vegas
相关产品推荐
相关产品推荐

