温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何在python中安装gdal

发布时间:2021-05-21 17:28:43 来源:亿速云 阅读:344 作者:Leah 栏目:开发技术

这篇文章将为大家详细讲解有关如何在python中安装gdal,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

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‑3.0.1‑cp38‑cp38‑win_amd64.whl

注:若用pip安装gdal会报错:

pip install -i 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是什么意思

Python是一种跨平台的、具有解释性、编译性、互动性和面向对象的脚本语言,其最初的设计是用于编写自动化脚本,随着版本的不断更新和新功能的添加,常用于用于开发独立的项目和大型项目。

关于如何在python中安装gdal就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI