python安装gdal的两种方法

yipeiwu_com5年前Python基础

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安装gdal的两种方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【听图阁-专注于Python设计】网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

相关文章

详解Python函数式编程—高阶函数

详解Python函数式编程—高阶函数

函数式编程就是一种抽象程度很高的编程范式,纯粹的函数式编程语言编写的函数没有变量,因此,任意一个函数,只要输入是确定的,输出就是确定的,这种纯函数我们称之为没有副作用。而允许使用变量的程...

python实现字符串中字符分类及个数统计

输入一个字符串,分别统计出其中英文字母、空格、数字和其它字符的个数,本文给出解决方法 编写思路: 1、字符串的遍历,和列表类似,可以把字符串当做元素都是一个字符的一个字符列表,它可以和列...

用Python实现web端用户登录和注册功能的教程

用Python实现web端用户登录和注册功能的教程

用户管理是绝大部分Web网站都需要解决的问题。用户管理涉及到用户注册和登录。 用户注册相对简单,我们可以先通过API把用户注册这个功能实现了: _RE_MD5 = re.compil...

python lambda表达式(匿名函数)写法解析

这篇文章主要介绍了python lambda表达式(匿名函数)写法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 # lamb...

python3大文件解压和基本操作

先说下:所谓的大文件并不是压缩文件有多大,几十兆的文件而是解压后几百兆。其中就遇到解压不成功的情况.、读小文件时成功,大文件时失败等 def unzip_to_txt_plus(z...