栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

尽管在虚拟环境中运行良好,但无法使用PyInstaller可执行文件导入Geopandas

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

尽管在虚拟环境中运行良好,但无法使用PyInstaller可执行文件导入Geopandas

看起来像是

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)

我希望这有助于使答案更完整,并且捆绑的应用程序能够按预期完成地理空间操作。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/410745.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号