Skip to content

Instantly share code, notes, and snippets.

@gboeing
Last active January 4, 2024 01:47
Show Gist options
  • Save gboeing/a6fcb39a9010d142446f4a83e43d8d6c to your computer and use it in GitHub Desktop.
Save gboeing/a6fcb39a9010d142446f4a83e43d8d6c to your computer and use it in GitHub Desktop.
Set up geospatial scientific Python with Miniconda on Windows

Set up geospatial scientific Python with Miniconda on Windows

Anaconda is an excellent, simple way to get Python up and running on your computer. But, it includes a lot of packages you'll never use but consume gigs and gigs of hard drive space. Instead, you can just install miniconda and then choose the individual packages you need. The steps below explain how to do this to set up a Python environment for geospatial data science. These steps are Windows-specific, but the same process works on Mac or Linux (just don't download the wheels from Gohlke - conda/pip install them directly). If you're having trouble, here are more detailed instructions on getting geopandas and geospatial Python up and running.

Install Miniconda

  • Download the Miniconda for Python 3.5 installer
  • Install miniconda to C:\Anaconda and set it as the system's default Python

Install packages into Miniconda's default environment

  • Download from Gohlke the wheels of rtree, basemap, gdal, shapely, fiona, pyproj for this version of Python and architecture (32 vs 64 bit) to your desktop:
  • Open a command prompt from your desktop, then run: conda install anaconda-client pywin32 psutil numexpr cython pytables sqlalchemy statsmodels bottleneck xlrd xlwt pillow matplotlib pandas scikit-learn jupyter requests networkx
  • Then install the packages not available with conda. Run (just use tab-complete to type in the names of the downloaded wheel files): pip install Rtree-whatever.whl basemap-whatever.whl GDAL-whatever.whl Shapely-whatever.whl Fiona-whatever.whl pyproj-whatever.whl geopy descartes geopandas osmnx
  • Add the path to GDAL (something like C:\Anaconda\Lib\site-packages\osgeo) to the Windows PATH environment variable

How to create a separate Python 2 virtual environment with conda

Some Python code or packages might still require Python 2 instead of the modern Python 3. This is easy to accomodate with conda by just setting up a Python 2 virtual environment.

  • Install Microsoft Visual C++ Compiler for Python 2.7
  • Create the virtual environment: conda create -n py2 python=2 anaconda-client pywin32 psutil numexpr cython pytables sqlalchemy statsmodels bottleneck xlrd xlwt pillow matplotlib pandas scikit-learn jupyter requests networkx
  • Activate the environment: activate py2
  • Download from Gohlke the wheels of rtree, basemap, gdal, shapely, fiona, pyproj (see links above) for this version of Python and architecture (32 vs 64 bit) and then install like: pip install Rtree-whatever.whl basemap-whatever.whl GDAL-whatever.whl Shapely-whatever.whl Fiona-whatever.whl pyproj-whatever.whl geopy descartes geopandas osmnx urbansim pandana
  • to exit the virtual environment: deactivate
  • to delete the virtual environment: conda remove -n py2 --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment