应公司同事的要求,编写了一个shp文件转自然资源部的txt格式的 python 脚本,但一直是代码能跑,打包后为exe后运行报错。今天抽空利用AI解决了这个问题。一下是报错内容和解决方案。
一、一开始我是直接运行的打包命令:
pyinstaller shpToTxtBatch3.0.py
然后就得到了下面的报错信息:
File "geopandas\io\file.py", line 289, in _read_file
File "geopandas\io\file.py", line 146, in _check_engine
ImportError: The 'read_file' function requires the 'pyogrio' or 'fiona' package,
but neither is installed or imports correctly.
Importing pyogrio resulted in: GDAL DLL could not be found. It must be on the system PATH.
Importing fiona resulted in: No module named 'fiona'
上面的报错说,找不到 pyogrio或者fiona, 我明确知道我代码里面没有 使用到 fiona,就重点去排查pyogrio,查看打包后的文件是存在 名为pyogrio的文件夹的。
二、解决方案(运行下面的命令)
将用到的库所有完整的直接打包进去。
pyinstaller --onedir --collect-all geopandas --collect-all pyogrio shpToTxtBatch3.0.py