Skip to content

Instantly share code, notes, and snippets.

@marjanmo
Last active September 5, 2017 13:24
Show Gist options
  • Save marjanmo/66a14b3cc475c6e35f279a297d98c825 to your computer and use it in GitHub Desktop.
Save marjanmo/66a14b3cc475c6e35f279a297d98c825 to your computer and use it in GitHub Desktop.
Setting up conda virtual environment for working with geospatial Python projects (Windows and Linux)

Many of the projects on my github require setting up its own conda virtual environment. Moreover, many python projects work with the geospatial stuff, so many system-wide dependencies have to be installed for the python geospatial libraries to work normally. This gist covers a typical workflow that needs to be executed, if it's your first time using a geospatial python-written project inside in a virtual environment:

LINUX

System requirements

  • Install GDAL:

    On Ubuntu and Debian, it is fairly easy:

sudo add-apt-repository ppa:ubuntugis-unstable
sudo apt-get install gdal-bin

Otherwise, there are plenty of internet resources that cover installing GDAL, e.g. this one.

  • Install miniconda:

    32 bit:

wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86.sh --no-check-certificate && bash Miniconda2-latest-Linux-x86.sh

64 bit:

wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh --no-check-certificate && bash Miniconda2-latest-Linux-x86_64.sh

WINDOWS:

System requirements

Geospatial Python libraries

Once you have installed conda and created a new dedicated virtual environment my_env, you have to populate it with needed Python libraries. Usually this is done by activating a virtual environment and calling conda install *library* or pip install *library*. Unfortunately, on Windows, many complex Python libraries aren't ready for such a simplicity yet.

  • The best way to install bit more specific Python libraries on Windows is by downloading a .whl file from the famous Gotche's unofficial Windows binaries for python packages. In order to use libraries, such as Geopandas, you have to manually download and install the following files, corresponding to your version of Python and OS (32bit or 64bit):

  • Acitvate the virtual environment that you want to populate these libraries with with: activate my_virtual_env

  • Install downloaded .whl files by pip install *.whl. Make sure you move to the download folder so you won't have to worry about absolute paths of wh files. Use tab for names autocomplete.

  • Remember to use this technique every time that normal pip install * or conda install * won't do it's job.

  • Add the path to GDAL (something like C:\Anaconda\Lib\site-packages\osgeo) to the Windows PATH environment variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment