ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

pyinstaller打包geopandas环境报错处理

2021-10-13 14:58:57  阅读:722  来源: 互联网

标签:exe pyinstaller geopandas py 报错 File gis path line


文章目录


首先使用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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有