如何解决OSMnx在Binder环境中运行时出现的ImportError报错
Binder中导入OSMnx触发ImportError报错
我尝试在Binder中使用OSMnx时收到如下报错信息:
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) /tmp/ipykernel_120/2784735849.py in <module> 1 import networkx as nx ----> 2 import osmnx as ox 3 4 get_ipython().run_line_magic('matplotlib', 'inline') 5 ox.config(log_console=True) /srv/conda/envs/notebook/site-packages/osmnx/__init__.py in <module> 1 """OSMnx init.""" 2 ----> 3 from ._api import * 4 from ._version import __version__ /srv/conda/envs/notebook/site-packages/osmnx/_api.py in <module> 1 """Expose most common parts of public API directly in `osmnx.` namespace.""" 2 ----> 3 from .bearing import add_edge_bearings 4 from .bearing import orientation_entropy 5 from .bearing import plot_orientation /srv/conda/envs/notebook/site-packages/osmnx/bearing.py in <module> 3 import warnings 4 ----> 5 import matplotlib.pyplot as plt 6 import networkx as nx 7 import numpy as np /srv/conda/envs/notebook/site-packages/matplotlib/__init__.py in <module> 105 # cbook must import matplotlib only within function 106 # definitions, so it is safe to import from it here. --> 107 from . import _api, cbook, docstring, rcsetup 108 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence 109 from matplotlib.cbook import mplDeprecation # deprecated /srv/conda/envs/notebook/site-packages/matplotlib/rcsetup.py in <module> 22 import numpy as np 23 ---> 24 from matplotlib import _api, animation, cbook 25 from matplotlib.cbook import ls_mapper 26 from matplotlib.colors import Colormap, is_color_like /srv/conda/envs/notebook/site-packages/matplotlib/animation.py in <module> 32 33 import numpy as np ---> 34 from PIL import Image 35 36 import matplotlib as mpl /srv/conda/envs/notebook/site-packages/PIL/Image.py in <module> 112 # Also note that Image.core is not a publicly documented interface, 113 # and should be considered private and subject to change. --> 114 from . import _imaging as core 115 116 if __version__ != getattr(core, "PILLOW_VERSION", None): ImportError: cannot import name '_imaging'
该报错不仅出现在自定义搭建的Binder环境中,使用官方提供的OSMnx示例Binder环境运行《OSMnx功能演示》笔记本的首个代码块时,也会触发相同错误。
临时修复方案
- 将OSMnx版本回退到1.0.1即可正常运行,该版本不会触发上述导入错误。
内容的提问来源于stack exchange,提问作者Sanne Hombroek
相关产品推荐
相关产品推荐

