其他分享
首页 > 其他分享> > pyinstaller打包geopandas环境报错处理

pyinstaller打包geopandas环境报错处理

作者:互联网

文章目录


首先使用pyinstaller -F main.py将代码打包成带黑窗口的exe,以下为会遇到的一些问题以及解决方法

1. 执行exe出现geopandas的迭代错误

报错信息如下:

(gis_data_process) D:\code\gis_data_processing>main.exe
Traceback (most recent call last):
  File "main.py", line 10, in <module>
    from gis_data_process import *
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "gis_data_process.py", line 7, in <module>
    import geopandas
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "geopandas\__init__.py", line 17, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "geopandas\datasets\__init__.py", line 6, in <module>
StopIteration
[24328] Failed to execute script 'main' due to unhandled exception!

解决方法如下:

  1. 注释geopandas\__init__.py中第17行代码 “import geopandas.datasets # noqa”
  2. 删除打包生成的build、dist和spec文件
  3. 重新使用pyinstaller -F main.py打包

2. 执行exe找不到fiona._shim

报错信息如下:

(gis_data_process) D:\code\gis_data_processing>main.exe
Unhandled exception in thread started by <bound method GISDataProcess.generate_file_execute of <__main__.GISDataProcess object at 0x0000021A0C5D8DC8>>
Traceback (most recent call last):
  File "main.py", line 156, in generate_file_execute
    generate_shapefile(file_path, shape_path)
  File "gis_data_process.py", line 172, in generate_shapefile
    kml_to_shapefile(kml_path, shape_path)
  File "gis_data_process.py", line 417, in kml_to_shapefile
    geojson_to_shapefile(geojson_path, shape_path)
  File "gis_data_process.py", line 220, in geojson_to_shapefile
    geometry = geopandas.read_file(geojson_path)
  File "geopandas\io\file.py", line 166, in _read_file
  File "geopandas\io\file.py", line 81, in _check_fiona
ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: No module named 'fiona._shim'

解决方法如下:

  1. 找到打包生成的.spec文件,找到hiddenimports,添加 “fiona._shim”
  2. 删除打包生成的build、dist目录
  3. 使用pyinstaller main.spec打包生成exe

3. 执行exe找不到fiona.shema

报错信息如下:

(gis_data_process) D:\code\gis_data_processing>main.exe
Unhandled exception in thread started by <bound method GISDataProcess.generate_file_execute of <__main__.GISDataProcess object at 0x00000220B655B5E8>>
Traceback (most recent call last):
  File "main.py", line 156, in generate_file_execute
    generate_shapefile(file_path, shape_path)
  File "gis_data_process.py", line 172, in generate_shapefile
    kml_to_shapefile(kml_path, shape_path)
  File "gis_data_process.py", line 417, in kml_to_shapefile
    geojson_to_shapefile(geojson_path, shape_path)
  File "gis_data_process.py", line 220, in geojson_to_shapefile
    geometry = geopandas.read_file(geojson_path)
  File "geopandas\io\file.py", line 166, in _read_file
  File "geopandas\io\file.py", line 81, in _check_fiona
ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: No module named 'fiona.schema'

解决方法如下:

  1. 找到打包生成的.spec文件,找到hiddenimports,添加 “fiona.schema”
  2. 删除打包生成的build、dist目录
  3. 使用pyinstaller main.spec打包生成exe

4. 总结

以上3步操作完成后,就可以成功打包成exe,但是打开exe是带有黑窗口的。可以将spec文件中的console=True改为console=False,再使用pyinstaller main.spec打包生成exe,这样就没有黑窗口

标签:exe,pyinstaller,geopandas,py,报错,File,gis,path,line
来源: https://blog.csdn.net/TaoismHuang/article/details/120742205