看起来像是
geopandas在init上积极加载其数据目录。它包含非python文件,这些非python文件会
pyinstaller在您的软件包中被忽略,因此要
geopandas在加载时找到它们,必须将它们显式打包。
“手动”过程花了我一段时间才能弄清楚,而我正在用
conda做我的软件包管理器(如果您不这样做,这些修改仍会为您提供帮助)。为了使此工作正常进行,我们需要修改首次
.spec运行时生成的文件
pyinstaller:
# -*- mode: python -*-import osfrom PyInstaller.utils.hooks import collect_data_files # this is very helpfulenv_path = os.environ['CONDA_PREFIX']dlls = os.path.join(env_path, 'DLLs')bins = os.path.join(env_path, 'Library', 'bin')paths = [ os.getcwd(), env_path, dlls, bins,]# these binary paths might be different on your installation. # modify as needed. # caveat emptorbinaries = [ (os.path.join(bins,'geos.dll'), ''), (os.path.join(bins,'geos_c.dll'), ''), (os.path.join(bins,'spatialindex_c-64.dll'), ''), (os.path.join(bins,'spatialindex-64.dll'),''),]hidden_imports = [ 'ctypes', 'ctypes.util', 'fiona', 'gdal', 'geos', 'shapely', 'shapely.geometry', 'pyproj', 'rtree', 'geopandas.datasets', 'pytest', 'pandas._libs.tslibs.timedeltas',]# other fancy pyinstaller stuff...a = Analysis(['run_it.py'], pathex=paths, # add all your paths binaries=binaries, # add the dlls you may need datas=collect_data_files('geopandas', subdir='datasets'), #this is the important bit for your particular error message hiddenimports=hidden_imports, # double tap hookspath=[], runtime_hooks=[], excludes=excludes, win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher)# remaining fancy pyinstaller stuff...那应该收集丢失的数据目录,并将其放在可执行文件可以找到的位置。
“自动”方式将是构建一个
hook-geopandas.py为您执行此操作的文件。
pyinstaller在构建时加载这些挂钩,以节省和共享这些技巧。实际上,已经有一个非常不错的挂钩文件
shapely(
geopandas依赖项之一),您可以在此处进行查看。
- - - 编辑 - - - -
我目前还正在构建一个依赖的项目,
geopandas并且由于这个问题,我意识到上述修复截至该日期(2018-08-23)尚不完整。
在我的run_it.py我已经包括了以下的测试,以确保
fiona和
gdal都打包到正确的包:
from osgeo import gdal, ogr, osrfrom fiona.ogrext import Iterator, ItemsIterator, KeysIteratorfrom geopandas import GeoDataframe
除非您是向导,否则此测试可能会失败。此垫片在我的.spec文件中为我工作:
_osgeo_pyds = collect_data_files('osgeo', include_py_files=True)osgeo_pyds = []for p, lib in _osgeo_pyds: if '.pyd' in p: osgeo_pyds.append((p, ''))binaries = osgeo_pyds + [ # your other binaries]a = Analysis( # include your kwargs)我希望这有助于使答案更完整,并且捆绑的应用程序能够按预期完成地理空间操作。



