I am trying to install 'GDAL' python package in conda. Following are the various steps I followed for the installation.
conda create -n gdal_py37 python=3.7
conda activate gdal_py37
pip install -r requirements.txt
From Anaconda Navigator-> environments-> 'gdal_py37' -> select gdal package from uninstalled packages -> Apply
Implemented below line of code in python
import gdal
Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_18824\1419450745.py in <module>
7 import os
8 import sys
----> 9 import gdal
10 import glob
11 from tqdm import tqdm
c:\Users\<<User>>\.conda\envs\gdal_py37\lib\site-packages\gdal.py in <module>
1 # import osgeo.gdal as a convenience
----> 2 from osgeo.gdal import deprecation_warn
3 deprecation_warn('gdal')
4
5 from osgeo.gdal import *
c:\Users\<<User>>\.conda\envs\gdal_py37\lib\site-packages\osgeo\__init__.py in <module>
19 fp.close()
20 return _mod
---> 21 _gdal = swig_import_helper()
22 del swig_import_helper
23 else:
c:\Users\<<User>>\.conda\envs\gdal_py37\lib\site-packages\osgeo\__init__.py in swig_import_helper()
15 if fp is not None:
...
--> 342 return _load(spec)
343
344 else:
ImportError: DLL load failed: The specified procedure could not be found.
How can I resolve this error?
There is probably a compatibility issue with another package. This can easily happen when you are using conda with pip
. Here are two things you should consider:
pip
because it often leads to package incompabilities as pointed out above. Use the conda package manager together with environment.yml
files (conda docs | managing environments)conda-forge
channel.Add the conda-forge
channel by running
conda config --add channels conda-forge
conda config --set channel_priority strict
If you did not remove your non-functioning environment yet, do it with conda env remove -n gdal_py37
.
Create a file environment.yml
which replaces your requirements.txt
and should look like this:
name: gdal_py37
channels:
- conda-forge
dependencies:
- gdal=3.5.2
- python=3.7
Create your environment with its dependencies by running:
conda env create -f environment.yml
Activate your environment with conda activate gdal_py37
.
Now start python
and run the following:
from osgeo import gdal