我使用Python多处理模块加速脚本中的地理处理功能。为此,我使用OGR,OSR和GDAL库。多处理在Linux OS中运行良好。但是,当我在Windows操作系统中执行脚本时,multiprocessing.Process命令不会启动任何功能。相反,我收到以下错误消息,表明找不到OGR,OSR和GDAL库(它们分布在一个包中):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\ArcGIS10.4\lib\multiprocessing\forking.py", line 380, in main
prepare(preparation_data)
File "C:\Python27\ArcGIS10.4\lib\multiprocessing\forking.py", line 495, in prepare
'__parents_main__', file, path_name, etc
File "C:\Christian\Projects\2016-07 Geodesic Polygon Buffer\jo\Geodesic_Buffering_Areas18_2-Multicore.py", line 1, in <module>
import multiprocessing, ogr, osr
File "C:\Python27\ArcGIS10.4\lib\site-packages\ogr.py", line 2, in <module>
from osgeo.gdal import deprecation_warn
File "C:\Python27\ArcGIS10.4\lib\site-packages\osgeo\__init__.py", line 21, in<module>
_gdal = swig_import_helper()
File "C:\Python27\ArcGIS10.4\lib\site-packages\osgeo\__init__.py", line 17, inswig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified procedure could not be found.
仅当从p.start()调用函数时才会发生这种情况:
import multiprocessing, ogr, osr
def func(abc):
print abc
if __name__ == '__main__':
p = multiprocessing.Process(target = func, args=('xyz',))
p.start() # This is where I get the error
p.join()
当我在不导入OGR和OSR库的情况下运行脚本时,从p.start()调用func()并且我没有收到任何错误消息。但是,两个库的导入在主要部分中工作正常。只有多处理调用函数时才会显示错误消息。
编辑:导入库在多处理之外工作:
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ogr
>>> import osr
>>> import osgeo.gdal
>>> import multiprocessing
>>> import something
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named something
>>>
出现此错误的原因是什么?这可能与分叉有关吗?如何在Windows操作系统中使用OGR,OSR和GDAL库进行多处理?
我在Windows中使用Python 2.7.10(32位),在Linux中使用Python 2.7.6(64位)。