本文主要是介绍pyinstaller打包geopandas环境报错处理,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 1. 执行exe出现geopandas的迭代错误
- 2. 执行exe找不到fiona._shim
- 3. 执行exe找不到fiona.shema
- 4. 总结
首先使用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_loadFile "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 677, in _load_unlockedFile "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_moduleFile "gis_data_process.py", line 7, in <module>import geopandasFile "<frozen importlib._bootstrap>", line 983, in _find_and_loadFile "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 677, in _load_unlockedFile "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_moduleFile "geopandas\__init__.py", line 17, in <module>File "<frozen importlib._bootstrap>", line 983, in _find_and_loadFile "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 677, in _load_unlockedFile "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_moduleFile "geopandas\datasets\__init__.py", line 6, in <module>
StopIteration
[24328] Failed to execute script 'main' due to unhandled exception!
解决方法如下:
- 注释geopandas\__init__.py中第17行代码 “import geopandas.datasets # noqa”
- 删除打包生成的build、dist和spec文件
- 重新使用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_executegenerate_shapefile(file_path, shape_path)File "gis_data_process.py", line 172, in generate_shapefilekml_to_shapefile(kml_path, shape_path)File "gis_data_process.py", line 417, in kml_to_shapefilegeojson_to_shapefile(geojson_path, shape_path)File "gis_data_process.py", line 220, in geojson_to_shapefilegeometry = geopandas.read_file(geojson_path)File "geopandas\io\file.py", line 166, in _read_fileFile "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'
解决方法如下:
- 找到打包生成的.spec文件,找到hiddenimports,添加 “fiona._shim”
- 删除打包生成的build、dist目录
- 使用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_executegenerate_shapefile(file_path, shape_path)File "gis_data_process.py", line 172, in generate_shapefilekml_to_shapefile(kml_path, shape_path)File "gis_data_process.py", line 417, in kml_to_shapefilegeojson_to_shapefile(geojson_path, shape_path)File "gis_data_process.py", line 220, in geojson_to_shapefilegeometry = geopandas.read_file(geojson_path)File "geopandas\io\file.py", line 166, in _read_fileFile "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'
解决方法如下:
- 找到打包生成的.spec文件,找到hiddenimports,添加 “fiona.schema”
- 删除打包生成的build、dist目录
- 使用pyinstaller main.spec打包生成exe
4. 总结
以上3步操作完成后,就可以成功打包成exe,但是打开exe是带有黑窗口的。可以将spec文件中的console=True改为console=False,再使用pyinstaller main.spec打包生成exe,这样就没有黑窗口
这篇关于pyinstaller打包geopandas环境报错处理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!