How to set up Python for geospatial science and computing
This tutorial explains how to install Python and useful packages for geospatial science and computing on MS Windows as a non-admin user.
1 Install Python
First and foremost, you need to install Python of course.
- Download the latest version of the installer from https://www.python.org/downloads/. Please use the recommended download (e.g., python-3.9.5-amd64.exe).
- Run the installer.
- Don’t install launcher for all users. You cannot use this option as a non-admin user.
- Add Python x.y to PATH. This option will make your life a little bit easier later.
- Customize installation.
- Customize install location. You may want to use the P drive so you can run this installation remotely from another computer. For example,
2 Install NumPy
Now, your Python is ready. Let’s install the NumPy package using pip. NumPy provides fundamental tools for scientific computing with Python.
- Hit Win + R.
pip install numpy
3 Upgrade pip
I’m getting a warning message about the pip version. It’s optional, but let’s upgrade pip.
python -m pip install --upgrade pip
4 Install Matplotlib
Matplotlib is a plotting package for Python.
pip install matplotlib
5 Install GDAL
The Geospatial Data Abstraction Library (GDAL) is probably one of the most important open-source geospatial libraries along with PROJ, coordinate transformation software. The GDAL package for Python is a wrapper around the GDAL library. Running
pip install GDAL fails because its compile environment is not set up. However, we can install an unofficial compiled package (wheel) from https://www.lfd.uci.edu/~gohlke/pythonlibs/.
- Download the wheel file for your Python version from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal. For example, if your Python version is 3.9.1, download
GDAL-3.3.0-cp39-cp39-win_amd64.whl. Here, cp39 means CPython (the C implementation of Python that we installed above) 3.9.
- Do you know where you downloaded this file? Change to that directory from the command window. For example, if you downloaded it to
C: cd C:\Users\USERNAME\Downloads
- Now, install the wheel file:
pip install GDAL-3.3.0-cp39-cp39-win_amd64.whl
6 Install JupyterLab
JupyterLab is the next generation of Jupyter, a language-agnostic web-based notebook that supports Python and other languages. Installing JupyterLab will install Jupyter and IPython, an interactive shell for Python.
pip install jupyterlab
It will start a local web server from where you started it and open a new tab in the browser. Avoid running it from
C:\ unless you’re an admin because non-admin users cannot create files in
If you want to kill this JupyterLab instance, hit Ctrl+C from the command window. Remember, it “kills” JupyterLab, so you want to save all your work first.
You can try Jupyter:
It looks similar to JupyterLab, but it will open new browser tabs for new notebooks unlike JupyterLab that implements its own tabbing environment.
Let’s try IPython as well:
7 Homework: Show me your JupyterLab
Set up your Python environment by following the above instructions and start JupyterLab.
- Create a new Python 3 Notebook.
- Type this code in a cell:
name = "FirstLastname" print("Hello " + name)
- Run it by hitting Shift+Enter.
- Take a screenshot of the result and submit it in FirstLastname_JupyterLab.png.