【发布时间】:2021-09-09 23:11:01
【问题描述】:
我尝试使用需要 shapely 模块的 natcap.invest 模块,并在我的项目中使用 rasterio 模块。如果我只导入 natcap.invest 模块,它可以成功运行。但是如果我同时导入 natcap.invest 和 rasterio,它似乎无法工作。
[case1] 当我 import rasterio before 运行主代码时,运行主代码时报:GEOSGeom_createLinearRing_r返回一个NULL指针。
[case2]当我import rasterio 之后我运行主代码成功,导入rasterio模块时报:ImportError: DLL load failed: the given module is not found.
代码如下:
import logging
import sys
import numpy as np
import natcap.invest.hydropower.hydropower_water_yield
import natcap.invest.utils
import xarray as xr
import rasterio # case 1
# main code
LOGGER = logging.getLogger(__name__)
root_logger = logging.getLogger()
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
fmt=natcap.invest.utils.LOG_FMT,
datefmt='%m/%d/%Y %H:%M:%S ')
handler.setFormatter(formatter)
logging.basicConfig(level=logging.INFO, handlers=[handler])
args = {
'biophysical_table_path': 'F:/biophysical_table_gura.csv',
'depth_to_root_rest_layer_path': 'F:/depth_to_root_restricting_layer_gura.tif',
'do_scarcity_and_valuation': False,
'eto_path': 'F:/reference_ET_gura.tif',
'lulc_path': 'F:/land_use_gura.tif',
'pawc_path': 'F:/plant_available_water_fraction_gura.tif',
'precipitation_path': 'F:/precipitation_gura.tif',
'results_suffix': 'temp1',
'seasonality_constant': '5',
'sub_watersheds_path': '',
'watersheds_path': 'F:/watershed_gura.shp',
'workspace_dir': 'F:/OUTPUT',
}
if __name__ == '__main__':
natcap.invest.hydropower.hydropower_water_yield.execute(args) # where error of case 1 occurs.
import rasterio # case 2 # where error of case 2 occurs.
有没有什么方案可以让我同时成功导入和使用这两个模块?
【问题讨论】:
-
我猜主要原因是rasterio和shapely不兼容,但我不知道如何处理。
标签: python python-import python-xarray shapely rasterio