使用 conda 安装 gdal?
Install gdal using conda?
我用过
conda install gdal
安装 GDAL 包。但是导入包的时候出现了如下错误
>>> from osgeo import gdal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()
File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so, 2): Library not loaded: libgdal.20.dylib
Referenced from: /Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so
Reason: image not found
>>> from osgeo import ogr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()
File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so, 2): Library not loaded: libgdal.20.dylib
Referenced from: /Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so
Reason: image not found
我应该怎么做才能在 Python 中导入 GDAL?
对于 windows 用户(截至 2015 年 12 月):
conda install gdal
conda upgrade numpy
安装 gdal 会降级 numpy,因此请重新升级它。
我最近有机会使用 windows 进行更改,令我惊喜的是 gdal "works" 现在很容易。
Windows+python+全世界的 gis 人都应该庆祝这一天。 (gdal-python 很容易进入 windows...不是说 windows 离 linux 更近了一步;))
您还可以使用频道 conda-forge
conda install -c conda-forge gdal
按照 anaconda website 上的建议。
我用过
conda install -c conda-forge gdal
在 Fedora 30 机器上,它让我走上了图书馆冲突地狱的道路!
conda install gdal
第一次尝试就成功了
我遇到了同样的问题,经过几天尝试不同的解决方案后,我发现问题出在Anaconda 版本和python 版本之间!如果您的系统上同时安装了 Python 和 Anaconda,请卸载 python 并使用 anaconda 提示 运行 :
pip 安装 gdal
刚才在conda的base环境下执行之前提出的命令出错:
conda install -c conda-forge gdal
这花了很长时间才 "solve environment",最后发现许多冲突导致安装停止。
鉴于此,我创建了一个单独的环境:
conda create -n gdal python=3.8
并通过以下方式激活它:
conda activate gdal
然后然后执行了第一个命令(以及all others listed in the documentation)。这工作速度很快,没有任何错误。
以下对我来说很可靠 Ubuntu 20.04:
conda update conda
sudo apt-get install libgdal-dev gdal-bin
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
# check gdal version with
gdal-config --version
echo '
name: raster-pipeline
channels:
- defaults
dependencies:
- python=3.7.*
- cython
- numpy
- ipython
- libspatialindex
- libgdal=USE_GDAL_VERSION
- gdal=USE_GDAL_VERSION
- pip
- pip:
- numpy>=1.18.5
- GDAL==USE_GDAL_VERSION
- pyproj>=2.6.1.post1
- rasterio>=1.1.5
' > raster_pipeline.yml
conda env create -f raster_pipeline.yml -v
conda activate raster_pipeline
python -c "from osgeo import gdal"
conda deactivate
这对我有用。希望它对某人有用。我正在使用 Ubuntu 20.04:它还使用 gdal
安装 osgeo
Step 1 : conda install -c conda-forge gdal
如果还有错误的话
Step 2 : conda config --set channel_priority strict”
Step 3 : conda update gdal
对于现有 conda-env,我在 Ubuntu 20.04 做了如下操作:
conda update conda
sudo apt-get install libgdal-dev gdal-bin
$export CPLUS_INCLUDE_PATH=/usr/include/gdal
$export C_INCLUDE_PATH=/usr/include/gdal
$gdal-config --version
gdal3.0.4
$whereis pip
/usr/local/anaconda3/bin/pip # anaconda's pip
$/usr/local/anaconda3/bin/pip install setuptools==57.4.0
$/usr/local/anaconda3/bin/pip install gdal==3.0.4
这对我有用
> CONDA_SUBDIR=osx-64 conda create -n my_env python=3.7
> conda activate my_env
> conda env config vars set CONDA_SUBDIR=osx-64
> conda install gdal
Now use,
> python3
> from osgeo import gdal
我用过
conda install gdal
安装 GDAL 包。但是导入包的时候出现了如下错误
>>> from osgeo import gdal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()
File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so, 2): Library not loaded: libgdal.20.dylib
Referenced from: /Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so
Reason: image not found
>>> from osgeo import ogr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()
File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so, 2): Library not loaded: libgdal.20.dylib
Referenced from: /Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so
Reason: image not found
我应该怎么做才能在 Python 中导入 GDAL?
对于 windows 用户(截至 2015 年 12 月):
conda install gdal
conda upgrade numpy
安装 gdal 会降级 numpy,因此请重新升级它。 我最近有机会使用 windows 进行更改,令我惊喜的是 gdal "works" 现在很容易。
Windows+python+全世界的 gis 人都应该庆祝这一天。 (gdal-python 很容易进入 windows...不是说 windows 离 linux 更近了一步;))
您还可以使用频道 conda-forge
conda install -c conda-forge gdal
按照 anaconda website 上的建议。
我用过
conda install -c conda-forge gdal
在 Fedora 30 机器上,它让我走上了图书馆冲突地狱的道路!
conda install gdal
第一次尝试就成功了
我遇到了同样的问题,经过几天尝试不同的解决方案后,我发现问题出在Anaconda 版本和python 版本之间!如果您的系统上同时安装了 Python 和 Anaconda,请卸载 python 并使用 anaconda 提示 运行 : pip 安装 gdal
刚才在conda的base环境下执行之前提出的命令出错:
conda install -c conda-forge gdal
这花了很长时间才 "solve environment",最后发现许多冲突导致安装停止。
鉴于此,我创建了一个单独的环境:
conda create -n gdal python=3.8
并通过以下方式激活它:
conda activate gdal
然后然后执行了第一个命令(以及all others listed in the documentation)。这工作速度很快,没有任何错误。
以下对我来说很可靠 Ubuntu 20.04:
conda update conda
sudo apt-get install libgdal-dev gdal-bin
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
# check gdal version with
gdal-config --version
echo '
name: raster-pipeline
channels:
- defaults
dependencies:
- python=3.7.*
- cython
- numpy
- ipython
- libspatialindex
- libgdal=USE_GDAL_VERSION
- gdal=USE_GDAL_VERSION
- pip
- pip:
- numpy>=1.18.5
- GDAL==USE_GDAL_VERSION
- pyproj>=2.6.1.post1
- rasterio>=1.1.5
' > raster_pipeline.yml
conda env create -f raster_pipeline.yml -v
conda activate raster_pipeline
python -c "from osgeo import gdal"
conda deactivate
这对我有用。希望它对某人有用。我正在使用 Ubuntu 20.04:它还使用 gdal
安装 osgeoStep 1 : conda install -c conda-forge gdal
如果还有错误的话
Step 2 : conda config --set channel_priority strict”
Step 3 : conda update gdal
对于现有 conda-env,我在 Ubuntu 20.04 做了如下操作:
conda update conda
sudo apt-get install libgdal-dev gdal-bin
$export CPLUS_INCLUDE_PATH=/usr/include/gdal
$export C_INCLUDE_PATH=/usr/include/gdal
$gdal-config --version
gdal3.0.4
$whereis pip
/usr/local/anaconda3/bin/pip # anaconda's pip
$/usr/local/anaconda3/bin/pip install setuptools==57.4.0
$/usr/local/anaconda3/bin/pip install gdal==3.0.4
这对我有用
> CONDA_SUBDIR=osx-64 conda create -n my_env python=3.7
> conda activate my_env
> conda env config vars set CONDA_SUBDIR=osx-64
> conda install gdal
Now use,
> python3
> from osgeo import gdal