pyinstaller打包中的大坑geopandas
pyinstaller打包中的大坑geopandas
ytkz一开始使用以下语句打包:
pyinstaller -F simplify.py
运行打包后的exe闪退,报错信息如下:
Traceback (most recent call last):
File "vector_simplify.py", line 673, in <module>
vector2simplify(a, b, c)
File "vector_simplify.py", line 643, in vector2simplify
find_intersections(shape_path, common_line)
File "vector_simplify.py", line 145, in find_intersections
gdf = gpd.read_file(shp_path)
File "geopandas\io\file.py", line 255, in _read_file
File "geopandas\io\file.py", line 114, in _check_engine
ImportError: The 'read_file' function requires the 'pyogrio' or 'fiona' package, but neither is installed or imports correctly.
Importing fiona resulted in: DLL load failed while importing _env: 找不到指定的模块。
Importing pyogrio resulted in: No module named 'pyogrio'
[24756] Failed to execute script 'simplify' due to unhandled exception!
解决办法:
修改spec文件,把缺失的fiona库的dll添加到spec文件中。
# -*- mode: python ; coding: utf-8 -*-
import glob, os
fiona_imports_paths = glob.glob(r'C:\Users\admin\site-packages\fiona.libs\*.dll')
fiona_imports = []
for item in fiona_imports_paths:
fiona_imports.append((item,'.'))
a = Analysis(
['simplify.py'],
pathex=[],
binaries=[],
datas=fiona_imports,
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='simplify',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['1.png'],
)
最后使用以下运行语句:
pyinstaller simplify.py