python安装gdal的两种方法
(编辑:jimmy 日期: 2024/11/20 浏览:3 次 )
1.不用手动下载文件,直接执行以下命令即可
conda install gdal
2.首先,下载gdal的whl文件 链接, 官网下载比较慢,GDAL-2.2.4-cp27-cp27m-win_amd64.whl
链接: https://pan.baidu.com/s/1prPHLJKwoKK505i5qTVZ7g
提取码: egj6
有百度云可以下载,然后放入本机目录。
这里目录有两种,一是放入anaconda安装目录的Scripts目录,我的是D:\anaconda\Scripts目录;二是放入Anaconda环境的Scripts目录,我的是D:\anaconda\envs\uav\Scripts(uav是我自己的环境,可通过命令conda create -n name python=3.6创建环境)。
最后,在D:\Anaconda3\Scripts目录下在空白处按住shift加右键打开cmd,输入以下命令即可。
pip install GDAL"external nofollow" href="https://pypi.tuna.tsinghua.edu.cn/simple">https://pypi.tuna.tsinghua.edu.cn/simple gdal
报错信息如下:
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting gdal Downloading https://pypi.tuna.tsinghua.edu.cn/packages/26/c6/f8846ba726b37f9a1099acb5bff43c309fb913577674c1ba491f6fc60598/GDAL-3.0.1.tar.gz (576kB) |████████████████████████████████| 583kB 810kB/s Building wheels for collected packages: gdal Building wheel for gdal (setup.py) ... error ERROR: Complete output from command /home/dennis/miniconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-i321u6em/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 /tmp/pip-wheel-aaneihet --python-tag cp37: ERROR: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.7 copying gdal.py -> build/lib.linux-x86_64-3.7 copying ogr.py -> build/lib.linux-x86_64-3.7 copying osr.py -> build/lib.linux-x86_64-3.7 copying gdalconst.py -> build/lib.linux-x86_64-3.7 copying gdalnumeric.py -> build/lib.linux-x86_64-3.7 creating build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/osr.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gnm.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/__init__.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/ogr.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdal.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.7/osgeo Fixing build/lib.linux-x86_64-3.7/gdal.py build/lib.linux-x86_64-3.7/ogr.py build/lib.linux-x86_64-3.7/osr.py build/lib.linux-x86_64-3.7/gdalconst.py build/lib.linux-x86_64-3.7/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/gdalconst.py build/lib.linux-x86_64-3.7/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/osr.py build/lib.linux-x86_64-3.7/osgeo/gnm.py build/lib.linux-x86_64-3.7/osgeo/__init__.py build/lib.linux-x86_64-3.7/osgeo/ogr.py build/lib.linux-x86_64-3.7/osgeo/gdal.py build/lib.linux-x86_64-3.7/osgeo/gdal_array.py Skipping optional fixer: ws_comma Fixing build/lib.linux-x86_64-3.7/gdal.py build/lib.linux-x86_64-3.7/ogr.py build/lib.linux-x86_64-3.7/osr.py build/lib.linux-x86_64-3.7/gdalconst.py build/lib.linux-x86_64-3.7/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/gdalconst.py build/lib.linux-x86_64-3.7/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/osr.py build/lib.linux-x86_64-3.7/osgeo/gnm.py build/lib.linux-x86_64-3.7/osgeo/__init__.py build/lib.linux-x86_64-3.7/osgeo/ogr.py build/lib.linux-x86_64-3.7/osgeo/gdal.py build/lib.linux-x86_64-3.7/osgeo/gdal_array.py Skipping optional fixer: ws_comma running build_ext gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o -std=c++11 building 'osgeo._gdal' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/extensions gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.7/extensions/gdal_wrap.o -std=c++11 -I/home/dennis/miniconda3/include cc1plus: warning: command line option ‘-Wstrict-prototypes' is valid for C/ObjC but not for C++ extensions/gdal_wrap.cpp:4075:1: error: ‘VSIDIR' does not name a type VSIDIR* wrapper_VSIOpenDir( const char * utf8_path, ^ extensions/gdal_wrap.cpp:4123:38: error: ‘VSIDIR' was not declared in this scope DirEntry* wrapper_VSIGetNextDirEntry(VSIDIR* dir) ^ extensions/gdal_wrap.cpp:4123:46: error: ‘dir' was not declared in this scope DirEntry* wrapper_VSIGetNextDirEntry(VSIDIR* dir) ^ extensions/gdal_wrap.cpp:4124:1: error: expected ‘,' or ‘;' before ‘{' token { ^ extensions/gdal_wrap.cpp:3225:7: warning: ‘char* get_aligned_buffer(char*, GDALDataType)' defined but not used [-Wunused-function] char* get_aligned_buffer(char* data, GDALDataType ntype) ^ extensions/gdal_wrap.cpp:3244:13: warning: ‘void update_buffer_size(void*, char*, char*, size_t)' defined but not used [-Wunused-function] static void update_buffer_size(void* obj, char* data, char* data_aligned, size_t buf_size) ^ extensions/gdal_wrap.cpp:3299:5: warning: ‘int GetUseExceptions()' defined but not used [-Wunused-function] int GetUseExceptions() { ^ extensions/gdal_wrap.cpp:3305:6: warning: ‘void UseExceptions()' defined but not used [-Wunused-function] void UseExceptions() { ^ extensions/gdal_wrap.cpp:3322:6: warning: ‘void DontUseExceptions()' defined but not used [-Wunused-function] void DontUseExceptions() { ^ extensions/gdal_wrap.cpp:3370:13: warning: ‘void ClearErrorState()' defined but not used [-Wunused-function] static void ClearErrorState() ^ error: command 'gcc' failed with exit status 1 ---------------------------------------- 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: Complete output from command /home/dennis/miniconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-i321u6em/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 /tmp/pip-record-axykekqk/install-record.txt --single-version-externally-managed --compile: ERROR: running install running build running build_py creating build creating build/lib.linux-x86_64-3.7 copying gdal.py -> build/lib.linux-x86_64-3.7 copying ogr.py -> build/lib.linux-x86_64-3.7 copying osr.py -> build/lib.linux-x86_64-3.7 copying gdalconst.py -> build/lib.linux-x86_64-3.7 copying gdalnumeric.py -> build/lib.linux-x86_64-3.7 creating build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/osr.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gnm.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/__init__.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/ogr.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdal.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.7/osgeo Fixing build/lib.linux-x86_64-3.7/gdal.py build/lib.linux-x86_64-3.7/ogr.py build/lib.linux-x86_64-3.7/osr.py build/lib.linux-x86_64-3.7/gdalconst.py build/lib.linux-x86_64-3.7/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/gdalconst.py build/lib.linux-x86_64-3.7/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/osr.py build/lib.linux-x86_64-3.7/osgeo/gnm.py build/lib.linux-x86_64-3.7/osgeo/__init__.py build/lib.linux-x86_64-3.7/osgeo/ogr.py build/lib.linux-x86_64-3.7/osgeo/gdal.py build/lib.linux-x86_64-3.7/osgeo/gdal_array.py Skipping optional fixer: ws_comma Fixing build/lib.linux-x86_64-3.7/gdal.py build/lib.linux-x86_64-3.7/ogr.py build/lib.linux-x86_64-3.7/osr.py build/lib.linux-x86_64-3.7/gdalconst.py build/lib.linux-x86_64-3.7/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/gdalconst.py build/lib.linux-x86_64-3.7/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/osr.py build/lib.linux-x86_64-3.7/osgeo/gnm.py build/lib.linux-x86_64-3.7/osgeo/__init__.py build/lib.linux-x86_64-3.7/osgeo/ogr.py build/lib.linux-x86_64-3.7/osgeo/gdal.py build/lib.linux-x86_64-3.7/osgeo/gdal_array.py Skipping optional fixer: ws_comma running build_ext gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o -std=c++11 building 'osgeo._gdal' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/extensions gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.7/extensions/gdal_wrap.o -std=c++11 -I/home/dennis/miniconda3/include cc1plus: warning: command line option ‘-Wstrict-prototypes' is valid for C/ObjC but not for C++ extensions/gdal_wrap.cpp:4075:1: error: ‘VSIDIR' does not name a type VSIDIR* wrapper_VSIOpenDir( const char * utf8_path, ^ extensions/gdal_wrap.cpp:4123:38: error: ‘VSIDIR' was not declared in this scope DirEntry* wrapper_VSIGetNextDirEntry(VSIDIR* dir) ^ extensions/gdal_wrap.cpp:4123:46: error: ‘dir' was not declared in this scope DirEntry* wrapper_VSIGetNextDirEntry(VSIDIR* dir) ^ extensions/gdal_wrap.cpp:4124:1: error: expected ‘,' or ‘;' before ‘{' token { ^ extensions/gdal_wrap.cpp:3225:7: warning: ‘char* get_aligned_buffer(char*, GDALDataType)' defined but not used [-Wunused-function] char* get_aligned_buffer(char* data, GDALDataType ntype) ^ extensions/gdal_wrap.cpp:3244:13: warning: ‘void update_buffer_size(void*, char*, char*, size_t)' defined but not used [-Wunused-function] static void update_buffer_size(void* obj, char* data, char* data_aligned, size_t buf_size) ^ extensions/gdal_wrap.cpp:3299:5: warning: ‘int GetUseExceptions()' defined but not used [-Wunused-function] int GetUseExceptions() { ^ extensions/gdal_wrap.cpp:3305:6: warning: ‘void UseExceptions()' defined but not used [-Wunused-function] void UseExceptions() { ^ extensions/gdal_wrap.cpp:3322:6: warning: ‘void DontUseExceptions()' defined but not used [-Wunused-function] void DontUseExceptions() { ^ extensions/gdal_wrap.cpp:3370:13: warning: ‘void ClearErrorState()' defined but not used [-Wunused-function] static void ClearErrorState() ^ error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Command "/home/dennis/miniconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-i321
总结
以上所述是小编给大家介绍的python安装gdal的两种方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
下一篇:线程安全及Python中的GIL原理分析