Article catalog
1. Iteration error of geopandas occurs when executing exe. 2. Fiona cannot be found when executing exe_ Shim3. Cannot find fiona.shema4. Summary by executing exe
First, use pyinstaller – F main.py to package the code into an EXE with a black window. The following are some problems and solutions
1. The iteration error of geopandas occurs when executing exe
The error information is as follows:
(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!
The solution is as follows:
comment geopandas\__ init__. Py line 17 code “import geopandas. Datasets # noqa” delete the build, dist and spec files generated by packaging and reuse pyinstaller – f main. Py packaging OL>
2. Execute exe and cannot find Fiona_ shim
The error information is as follows:
(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'
The solution is as follows:
find the. Spec file generated by packaging, find hiddenimports, add “Fiona. _shim”, delete the build and dist directories generated by packaging, and use pyinstaller main.spec to package and generate exe OL>
3. Fiona.shema cannot be found by executing exe
The error information is as follows:
(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'
The solution is as follows:
find the. Spec file generated by packaging, find hiddenimports, add “Fiona. Schema”, delete the build and dist directories generated by packaging, and use pyinstaller main.spec to package and generate exe OL>
4. Summary
After the above three steps are completed, you can successfully package into exe, but opening exe has a black window. You can change console = true to console = false in the spec file, and then use pyinstaller main.spec to package and generate exe, so that there is no black window