Search code examples
pythonanacondagdalgeopandas

Unable to install GeoPandas/GDAL


I am trying to install geopandas.

To achieve that I need to install the GDAL dependency.

I am neither able to intall geopandas nor able to install GDAL.

Environment Anaconda 4, Python 3.6

Methods I have tried:

  1. pip intall appropriate library
  2. conda install appropriate library
  3. Downloaded suggested wheels from various thredas still failed
  4. Tried to setup environements custom ones then also failed.

Solution

  • This works without any issue:

    # create environment called geo and install python 3.6 and geo panda from conda-forge channel
    conda create -n geo  -c conda-forge  python=3.6 geopandas
    

    To use geopanda, activate the environment geo and all is well

    conda activate geo
    # test that geopanda imports okay
    python -c "import geopanda"
    

    If no error the geopanda was correctly install in your geo environment

    If you need other packages to be install in your geo conda environment, then add them with

    conda install -n geo PACKAGENAME PACKAGE2
    

    If you are using Spyder, you need to have spyder in your environment too:

    conda install -n geo spyder
    conda activate geo
    spyder
    

    Now your spyder has access to all packages in geo environment. If you do not wish to install spyder in this environment and use spyder in base environment instead, you can do

    # install spyder kernel
     conda install -n geo spyder-kernels
    
    # get the path to geo python executable and copy the path
    conda activate geo
    python -c "import sys; print(sys.executable)"
    
    # deactivate geo
    conda deactivate 
    
    # this returns you to base environment 
    # open spyder from base
    
    spyder
    

    In spyder GUI, head to Tool > Preferences > Python Interpreter > Use the following interpreter and paste the geo environment python executable path.

    I believe there is an icon at the lower right of spyder that allows you to toggle between environments. But not sure if it is still there as last time I used spyder was 2016.