1.错误信息
ERROR: Command errored out with exit status 1:
command: 'c:\python37\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\11931\\AppData\\Local\\Temp\\pip-install-yy0nccti\\fiona\\setup.py'"'"'; __file__='"'"'C:\\Users\\11931\\AppData\\Local\\Temp\\pip-install-yy0nccti\\fiona\\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\11931\AppData\Local\Temp\pip-pip-egg-info-kk517f2i'
cwd: C:\Users\11931\AppData\Local\Temp\pip-install-yy0nccti\fiona\
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.
2.解决方案
这里的错误大概率是gdal造成的,但是我已经安装了gdal,并且一直在用,所以可能是某个参数设置的问题。
查看geopandas文档(https://geopandas.org/install.html#dependencies),发现geopandas的依赖包是:
-
pandas (version 0.23.4 or later)
所以这个问题可能是出在fiona上。
于是尝试pip install fiona,失败,报错与上述错误一致,说明是fiona的问题,重新下载fiona(https://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona),然后离线安装,之后再pip install geopandas,成功
类似问题可以考虑是否是下述依赖包的问题:
pip install wheel
pip install pipwin
# 刷新pipwin
pipwin refresh
# 一定要先gdal,再fiona,再geopandas, 且都用pipwin 比较保险
pipwin install numpy
pipwin install pandas
pipwin install shapely
pipwin install gdal
pipwin install fiona
pipwin install pyproj
pipwin install six
pipwin install rtree
pipwin install geopandas
3.2022年1月10日修正解决方案
最近重新部署了虚拟环境,python版本如下:
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
在用pipwin安装gdal, fiona, geopandas 之后报错
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python39\envs\proj\lib\site-packages\fiona\__init__.py", line 89, in <module>
from fiona.collection import BytesCollection, Collection
File "C:\Python39\envs\proj\lib\site-packages\fiona\collection.py", line 11, in <module>
from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
ImportError: DLL load failed while importing ogrext: The specified module could not be found.
uninstall之后,下载whl文件,重新pip install即可。下载链接:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
用的时候又出现问题,检查c++compiler
checked if my computer has a c++ compiler for python
Latest supported Visual C++ Redistributable downloads | Microsoft Docs
最后还是重新新建了虚拟环境,从安装pipwin开始,依次安装numpy,shapely,pyshp,pyproj,gdal,fiona,pandas,geopandas搞定。
2024年10月26日修改:
gdal whl下载链接更新为Releases · cgohlke/geospatial-wheels