pyinstaller打包geopandas环境报错处理

2024-03-17 08:32

本文主要是介绍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!

解决方法如下:

  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_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'

解决方法如下:

  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_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'

解决方法如下:

  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,这样就没有黑窗口

这篇关于pyinstaller打包geopandas环境报错处理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/818406

相关文章

linux打包解压命令方式

《linux打包解压命令方式》文章介绍了Linux系统中常用的打包和解压命令,包括tar和zip,使用tar命令可以创建和解压tar格式的归档文件,使用zip命令可以创建和解压zip格式的压缩文件,每... 目录Lijavascriptnux 打包和解压命令打包命令解压命令总结linux 打包和解压命令打

Python自动化处理手机验证码

《Python自动化处理手机验证码》手机验证码是一种常见的身份验证手段,广泛应用于用户注册、登录、交易确认等场景,下面我们来看看如何使用Python自动化处理手机验证码吧... 目录一、获取手机验证码1.1 通过短信接收验证码1.2 使用第三方短信接收服务1.3 使用ADB读取手机短信1.4 通过API获取

Python自动化Office文档处理全攻略

《Python自动化Office文档处理全攻略》在日常办公中,处理Word、Excel和PDF等Office文档是再常见不过的任务,手动操作这些文档不仅耗时耗力,还容易出错,幸运的是,Python提供... 目录一、自动化处理Word文档1. 安装python-docx库2. 读取Word文档内容3. 修改

将java程序打包成可执行文件的实现方式

《将java程序打包成可执行文件的实现方式》本文介绍了将Java程序打包成可执行文件的三种方法:手动打包(将编译后的代码及JRE运行环境一起打包),使用第三方打包工具(如Launch4j)和JDK自带... 目录1.问题提出2.如何将Java程序打包成可执行文件2.1将编译后的代码及jre运行环境一起打包2

IDEA编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

配置springboot项目动静分离打包分离lib方式

《配置springboot项目动静分离打包分离lib方式》本文介绍了如何将SpringBoot工程中的静态资源和配置文件分离出来,以减少jar包大小,方便修改配置文件,通过在jar包同级目录创建co... 目录前言1、分离配置文件原理2、pom文件配置3、使用package命令打包4、总结前言默认情况下,

使用C++将处理后的信号保存为PNG和TIFF格式

《使用C++将处理后的信号保存为PNG和TIFF格式》在信号处理领域,我们常常需要将处理结果以图像的形式保存下来,方便后续分析和展示,C++提供了多种库来处理图像数据,本文将介绍如何使用stb_ima... 目录1. PNG格式保存使用stb_imagephp_write库1.1 安装和包含库1.2 代码解

在Mysql环境下对数据进行增删改查的操作方法

《在Mysql环境下对数据进行增删改查的操作方法》本文介绍了在MySQL环境下对数据进行增删改查的基本操作,包括插入数据、修改数据、删除数据、数据查询(基本查询、连接查询、聚合函数查询、子查询)等,并... 目录一、插入数据:二、修改数据:三、删除数据:1、delete from 表名;2、truncate