文章目录
首先使用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!
解决方法如下:
- 注释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_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'
解决方法如下:
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'
解决方法如下:
4. 总结
以上3步操作完成后,就可以成功打包成exe,但是打开exe是带有黑窗口的。可以将spec文件中的console=True改为console=False,再使用pyinstaller main.spec打包生成exe,这样就没有黑窗口
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。