用pip安装gdal会报错:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gdal
错误代码如下:
原因:GDAL不是纯净的python库,无法像pip install requests
这样安装库文件。
Building wheel for gdal (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'd:\program\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\PC-CYQ\\AppData\\Local\\Temp\\pip-install-n61e5cwp\\gdal\\setup.py'"'"'; __file__='"'"'C:\\Users\\PC-CYQ\\AppData\\Local\\Temp\\pip-install-n61e5cwp\\gdal\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\PC-CYQ\AppData\Local\Temp\pip-wheel-b1i402a_'
cwd: C:\Users\PC-CYQ\AppData\Local\Temp\pip-install-n61e5cwp\gdal\
Complete output (32 lines):
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
copying gdal.py -> build\lib.win-amd64-3.6
copying ogr.py -> build\lib.win-amd64-3.6
copying osr.py -> build\lib.win-amd64-3.6
copying gdalconst.py -> build\lib.win-amd64-3.6
copying gdalnumeric.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\osgeo
copying osgeo\gdal.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\gdalconst.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\gdalnumeric.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\gdal_array.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\gnm.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\ogr.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\osr.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\__init__.py -> build\lib.win-amd64-3.6\osgeo
Fixing build\lib.win-amd64-3.6\gdal.py build\lib.win-amd64-3.6\ogr.py build\lib.win-amd64-3.6\osr.py build\lib.win-amd64-3.6\gdalconst.py build\lib.win-amd64-3.6\gdalnumeric.py build\lib.win-amd64-3.6\osgeo\gdal.py build\lib.win-amd64-3.6\osgeo\gdalconst.py build\lib.win-amd64-3.6\osgeo\gdalnumeric.py build\lib.win-amd64-3.6\osgeo\gdal_array.py build\lib.win-amd64-3.6\osgeo\gnm.py build\lib.win-amd64-3.6\osgeo\ogr.py build\lib.win-amd64-3.6\osgeo\osr.py build\lib.win-amd64-3.6\osgeo\__init__.py
Skipping optional fixer: ws_comma
Fixing build\lib.win-amd64-3.6\gdal.py build\lib.win-amd64-3.6\ogr.py build\lib.win-amd64-3.6\osr.py build\lib.win-amd64-3.6\gdalconst.py build\lib.win-amd64-3.6\gdalnumeric.py build\lib.win-amd64-3.6\osgeo\gdal.py build\lib.win-amd64-3.6\osgeo\gdalconst.py build\lib.win-amd64-3.6\osgeo\gdalnumeric.py build\lib.win-amd64-3.6\osgeo\gdal_array.py build\lib.win-amd64-3.6\osgeo\gnm.py build\lib.win-amd64-3.6\osgeo\ogr.py build\lib.win-amd64-3.6\osgeo\osr.py build\lib.win-amd64-3.6\osgeo\__init__.py
Skipping optional fixer: ws_comma
running build_ext
building 'osgeo._gdal' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\extensions
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -Id:\program\anaconda3\include -Id:\program\anaconda3\include -Id:\program\anaconda3\lib\site-packages\numpy\core\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" /EHsc /Tpextensions/gdal_wrap.cpp /Fobuild\temp.win-amd64-3.6\Release\extensions/gdal_wrap.obj
gdal_wrap.cpp
extensions/gdal_wrap.cpp(3173): fatal error C1083: Cannot open include file: 'cpl_port.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Failed building wheel for gdal
Running setup.py clean for gdal
Failed to build gdal
Installing collected packages: gdal
Running setup.py install for gdal ... error
ERROR: Command errored out with exit status 1:
command: 'd:\program\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\PC-CYQ\\AppData\\Local\\Temp\\pip-install-n61e5cwp\\gdal\\setup.py'"'"'; __file__='"'"'C:\\Users\\PC-CYQ\\AppData\\Local\\Temp\\pip-install-n61e5cwp\\gdal\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\PC-CYQ\AppData\Local\Temp\pip-record-rqe9ylsx\install-record.txt' --single-version-externally-managed --compile --install-headers 'd:\program\anaconda3\Include\gdal'
cwd: C:\Users\PC-CYQ\AppData\Local\Temp\pip-install-n61e5cwp\gdal\
Complete output (32 lines):
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
copying gdal.py -> build\lib.win-amd64-3.6
copying ogr.py -> build\lib.win-amd64-3.6
copying osr.py -> build\lib.win-amd64-3.6
copying gdalconst.py -> build\lib.win-amd64-3.6
copying gdalnumeric.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\osgeo
copying osgeo\gdal.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\gdalconst.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\gdalnumeric.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\gdal_array.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\gnm.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\ogr.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\osr.py -> build\lib.win-amd64-3.6\osgeo
copying osgeo\__init__.py -> build\lib.win-amd64-3.6\osgeo
Fixing build\lib.win-amd64-3.6\gdal.py build\lib.win-amd64-3.6\ogr.py build\lib.win-amd64-3.6\osr.py build\lib.win-amd64-3.6\gdalconst.py build\lib.win-amd64-3.6\gdalnumeric.py build\lib.win-amd64-3.6\osgeo\gdal.py build\lib.win-amd64-3.6\osgeo\gdalconst.py build\lib.win-amd64-3.6\osgeo\gdalnumeric.py build\lib.win-amd64-3.6\osgeo\gdal_array.py build\lib.win-amd64-3.6\osgeo\gnm.py build\lib.win-amd64-3.6\osgeo\ogr.py build\lib.win-amd64-3.6\osgeo\osr.py build\lib.win-amd64-3.6\osgeo\__init__.py
Skipping optional fixer: ws_comma
Fixing build\lib.win-amd64-3.6\gdal.py build\lib.win-amd64-3.6\ogr.py build\lib.win-amd64-3.6\osr.py build\lib.win-amd64-3.6\gdalconst.py build\lib.win-amd64-3.6\gdalnumeric.py build\lib.win-amd64-3.6\osgeo\gdal.py build\lib.win-amd64-3.6\osgeo\gdalconst.py build\lib.win-amd64-3.6\osgeo\gdalnumeric.py build\lib.win-amd64-3.6\osgeo\gdal_array.py build\lib.win-amd64-3.6\osgeo\gnm.py build\lib.win-amd64-3.6\osgeo\ogr.py build\lib.win-amd64-3.6\osgeo\osr.py build\lib.win-amd64-3.6\osgeo\__init__.py
Skipping optional fixer: ws_comma
running build_ext
building 'osgeo._gdal' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\extensions
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -Id:\program\anaconda3\include -Id:\program\anaconda3\include -Id:\program\anaconda3\lib\site-packages\numpy\core\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" /EHsc /Tpextensions/gdal_wrap.cpp /Fobuild\temp.win-amd64-3.6\Release\extensions/gdal_wrap.obj
gdal_wrap.cpp
extensions/gdal_wrap.cpp(3173): fatal error C1083: Cannot open include file: 'cpl_port.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'd:\program\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\PC-CYQ\\AppData\\Local\\Temp\\pip-install-n61e5cwp\\gdal\\setup.py'"'"'; __file__='"'"'C:\\Users\\PC-CYQ\\AppData\\Local\\Temp\\pip-install-n61e5cwp\\gdal\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\PC-CYQ\AppData\Local\Temp\pip-record-rqe9ylsx\install-record.txt' --single-version-externally-managed --compile --install-headers 'd:\program\anaconda3\Include\gdal' Check the logs for full command output.
解决办法:
根据自己的python版本,下载对应的GDAL安装文件
1.官网下载,下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
可能下载缓慢,或下载失败
2.网盘下载:
GDAL-2.2.4-cp36-cp36m-win_amd64.whl和GDAL-2.2.4-cp37-cp37m-win_amd64.whl:
https://pan.baidu.com/s/1yyz4eERmZgzAwTZryrI1dA 密码: 468c
GDAL-2.2.4-cp27-cp27m-win_amd64.whl:
https://pan.baidu.com/s/1Yfj4tcgJ2iSxqEc3XC39Hw 密码:9hrj
安装:
pip install GDAL-2.2.4-cp36-cp36m-win_amd64.whl