问题描述:
PythonPIE版本:0.1.4
python版本:3.7.10
conda版本:4.10.0
在Conda环境中使用PIE的Python SDK遇到如下报错:
>>> import pie
## 输出
OSError Traceback (most recent call last)
<ipython-input-5-a1c6718efd24> in <module>
----> 1 import pie
2 # import pie.pieleaflet as pieleaflet
3
4 # 使用用户在平台上注册时的用户名/密码
5 # pie.initialize("**", "**")
D:\anaconda3\envs\pie_dev\lib\site-packages\pie\__init__.py in <module>
12 from .imageCollection import PIEImageCollection as ImageCollection
13 from .kernel import PIEKernel as Kernel
---> 14 from .map import PIEMap as Map
15 from .reducer import PIEReducer as Reducer
16 from .projection import PIEProjection as Projection
D:\anaconda3\envs\pie_dev\lib\site-packages\pie\map.py in <module>
11
12 import folium
---> 13 import ipyleaflet
14 from folium import GeoJson, features, vector_layers
15 # from folium.plugins import TileLayerWithHeaders
D:\anaconda3\envs\pie_dev\lib\site-packages\ipyleaflet\__init__.py in <module>
9
10 try:
---> 11 from .leaflet import * # noqa
12 from .basemaps import basemaps # noqa
13 except ImportError:
D:\anaconda3\envs\pie_dev\lib\site-packages\ipyleaflet\leaflet.py in <module>
21
22 from branca.colormap import linear, ColorMap
---> 23 from shapely import geometry, wkt
24
25 from ._version import EXTENSION_VERSION
D:\anaconda3\envs\pie_dev\lib\site-packages\shapely\geometry\__init__.py in <module>
2
3
----> 4 from .base import CAP_STYLE, JOIN_STYLE
5 from .geo import box, shape, asShape, mapping
6 from .point import Point, asPoint
D:\anaconda3\envs\pie_dev\lib\site-packages\shapely\geometry\base.py in <module>
17
18 from shapely.affinity import affine_transform
---> 19 from shapely.coords import CoordinateSequence
20 from shapely.errors import WKBReadingError, WKTReadingError
21 from shapely.geos import WKBWriter, WKTWriter
D:\anaconda3\envs\pie_dev\lib\site-packages\shapely\coords.py in <module>
6 from ctypes import byref, c_double, c_uint
7
----> 8 from shapely.geos import lgeos
9 from shapely.topology import Validating
10
D:\anaconda3\envs\pie_dev\lib\site-packages\shapely\geos.py in <module>
152 if os.getenv('CONDA_PREFIX', ''):
153 # conda package.
--> 154 _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
155 else:
156 try:
D:\anaconda3\envs\pie_dev\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
362
363 if handle is None:
--> 364 self._handle = _dlopen(self._name, mode)
365 else:
366 self._handle = handle
OSError: [WinError 126] 找不到指定的模块。
原因分析:
在Traceback的报错消息中,可能发现是conda环境`shapely`库的调用出现问题 152 if os.getenv('CONDA_PREFIX', ''):
153 # conda package.
--> 154 _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
155 else:
156 try:
遂搜索shapely库的import问题,在StackOverflow中找到相关解答。
解决方案:
安装完毕Conda环境的PIE的python SDK后,再用Conda重装一下Shapely库
conda install shapely
成功导入pie