應公司同事的要求,編寫了一個shp文件轉(zhuǎn)自然資源部的txt格式的 python 腳本,但一直是代碼能跑,打包后為exe后運行報錯。今天抽空利用AI解決了這個問題。一下是報錯內(nèi)容和解決方案。
一、一開始我是直接運行的打包命令:
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