写在前面:写这篇的目的是因为被gdal对应版本包的安装折磨的半死,最后找到一个适用于自己的成功安装的办法
我的问题:
目前python主流工具包的二进制whl版本的下载地址 只提供了最高版本gdal=3.1.2的whl版,没有之前的老版本的whl了,下载whl进行离线安装固然很安逸,但是,我发现这个版本的gdal没法使用ReadAsArray(),即无法读为python操作的array数据形式。因此,需要卸载gdal3.1.2版本,安装3.0.2版本。
from osgeo import gdal
datasets = gdal.Open(file_path)
SubDatasets = datasets.GetSubDatasets()
band1 = gdal.Open(SubDatasets[0][0])
dts = band1.ReadAsArray()
正文:
下面正式介绍我的安装办法:
**♥step1:**打开“C:\Users\Administrator\Anaconda3\Lib\site-packages”路径,我安装anconda时使用默认路径,依据自己安装路径找到“Anaconda3\Lib\site-packages”所在位置,然后打开此路径下的cmd;
**♥step2:**在cmd中输入:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
更新pip
**♥step3:**输入
conda search gdal
查看清华源路径下的版本,发现有gdal3.0.2版本,当然你也可以安装更低版本
**♥step4:**输入
conda install gdal=3.0.2
如果没有报错,可以输入pip list去查看是否有gdal包以及对应得版本。
以上,提供一种安装思路♥
p.s.我在使用conda install gdal=3.0.2中还出现了一个报错:
InvalidArchiveError('Error with archive C:\\Users\\Administrator\\Anaconda3\\pkgs\\libboost-1.67.0-hd9e427e_4.tar.bz2. You probably need to delete and re-download or re-create this file. Message from libarchive was:\n\nCould not unlink',) InvalidArchiveError('Error with archive C:\\Users\\Administrator\\Anaconda3\\pkgs\\icc_rt-2019.0.0-h0cc432a_1.tar.bz2. You probably need to delete and re-download or re-create this file. Message from libarchive was:\n\nCould not unlink',) InvalidArchiveError('Error with archive C:\\Users\\Administrator\\Anaconda3\\pkgs\\postgresql-11.2-h3235a2c_0.tar.bz2. You probably need to delete and re-download or re-create this file. Message from libarchive was:\n\nCould not unlink',)
我的解决办法是:conda install libboost,然后再重新conda install gdal=3.0.2就可以了