1. 程式人生 > 其它 >A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment

A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment

技術標籤:python各種疑難雜症python

問題描述:

windows10系統下python3.7安裝geopandas庫時遇到如下問題

    ERROR: Command errored out with exit status 1:
     command: 'd:\nap_venv\scripts\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\HM\\AppData\\Local\\Temp\\pip-install-62cmer82\\fiona_c0895a4e03664cbc93131ee63c3ba5da\\setup.py'
"'"'; __file__='"'"'C:\\Users\\HM\\AppData\\Local\\Temp\\pip-install-62cmer82\\fiona_c0895a4e03664cbc93131ee63c3ba5da\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"
'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\HM\AppData\Local\Temp\pip-pip-egg-info-_ayzhxnx' cwd: C:\Users\HM\AppData\Local\Temp\pip-install-62cmer82\fiona_c0895a4e03664cbc93131ee63c3ba5da\ Complete output (
1 lines): A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable. ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

原因分析:

安裝geopandas庫時會自動安裝Fiona庫,實際上這個錯誤是安裝Fiona時報的,大概原因是GDAL沒配置好


解決方案:

1、首先下載所需的gdal檔案-----GDAL.whl檔案下載地址

2、下載完成後使用pip安裝

pip install GDAL-3.1.4-cp37-cp37m-win_amd64.whl

3、安裝完成後新增名稱為GDAL_DATA的環境變數(具體位置在python資料夾記憶體放各種庫的位置site-packages\osgeo\data\gdal)

set GDAL_DATA=%GDAL_DATA%;D:\nap_venv\Lib\site-packages\osgeo\data\gdal

這個set是臨時設定變數,僅在當前cmd有效

4、下載Fiona檔案-----Fiona.whl檔案下載地址

5、下載完成後使用pip安裝

pip install Fiona-1.8.18-cp37-cp37m-win_amd64.whl

6、成功安裝Fiona後再使用pip安裝geopandas

pip install geopandas -i https://pypi.douban.com/simple/

最後geopandas就能安裝成功了
在這裡插入圖片描述