eds

Installing Python and JupyterLab

Tutorial

To install Python, JupyterLab, and the packages for the Environmental Data Science course read the instructions below or watch the video:

Overivew

In this course we will use Python with Jupyterlab, which is an open-source interactive development environment (IDE) that facilitates data science and scientific computing in Python through a web-based interface.

You can install Python using different methods:

This tutorial shows you how to:

Installing Python, JupyterLab, and required libraries with Miniconda

1. Install Python with Miniconda

You can easily install Python through Minoconda from Minconda webpage. You can find more information at GeoPython - Installing Python.

After the installation is complete, from Windows Star Menu, open Anaconda Prompt(Miniconda3) and type:

python --version

This will return to you the Python version that you have installed (e.g., Python 3.11.5).

Note: Make sure you that you have a 64-bit system. If you do not know: Use the search icon near “Start Menu” and search for “About” that will take you to”Settings”: “About” where you can know if you have a 32-bit or 64-bit processor.

2. Install and run Jupyterlab

You do not want to use Python in a black screen, so you need to install a graphical user interface(GUI). For programming languages, a GUI is called interactive development environment (IDE). The IDE that we will use for this course is Jupyterlab, which is an open-source IDE for Python, Julia, R, MATLAB/Octave, and few other programming languages.

In Python, we generally use pip or conda for installation. For details about JupyterLab installation, check the JupyterLab documentation, or follow these steps:

From the Windows Start menum, search for and open your Anaconda Prompt(Miniconda3), and install JupyterLab with pip by running this command:

pip install jupyterlab

Alternatively, you can install JupyterLab with conda with conda-forge channel by running this command:

conda install -c conda-forge jupyterlab

Once installed, launch JupyterLab with:

jupyter lab

3. Create Jupyterlab shortcut

Each time you use JupterLab, you do not want to open an Anaconda Prompt(Miniconda3) and type jupyter lab. You can create a shortcut to automatically lunch JupyterLab following these steps.

Create Anaconda Prompt Shortcut:

Customize Anaconda Prompt Shortcut:

4. Change JupyterLab shortcut icon (optional)

In case you want your icon to look nice

5. Install basic libraries

From the miniconda terminal install these libraries one by one. You can install them now or before each lesson.

Basic libraries: Pandas, NumPy and matplotlib :

pip install pyarrow pandas matplotlib numpy lckr_jupyterlab_variableinspector

Gridded data libraries: Xarray and CartoPy

pip install xarray netCDF4 cartopy

Statistical analysis and machine learning libraries:

pip install scipy seaborn statsmodels scikit-learn shap tensorflow

Google Earth engine (GEE) libraries:

pip install earthengine-api geemap ipywidgets

Automated data download

pip install copernicusmarine dataretrieval requests

Note: dataretrieval retrieves the major data types of USGS hydrology data that are available on the Web, as well as data from the Water Quality Portal (WQP), which currently houses water quality data from the EPA, USDA and USGS. Direct USGS data is obtained from a service called the National Water Information System (NWIS).

Jupyter AI facilitates AI coding assistance by bring language models such as ChatGPT to your Jupyter environment. You first need to have an API key for your language model to work. For example, if you want to use ChatGPT, check this file for OpenAI API key. Also, the installation time can be long, so you need to be patient.

To install Jupyter-AI with dependencies for all supported language models (not recommended):

pip install jupyter-ai[all]

To install Jupyter-AI wit with dependencies of selected model providers such as OpenAI, e.g., ChatGPT and Google, e.g., Gemini (recommended):

pip install jupyter-ai langchain-openai langchain-google-genai

The above comand provides two examples, but you can check the model provider table for information on supported providers and their dependencies.

Note: Jupyter AI may not work for the current python or JupyterLab version. You might need to upgrade/downgrade your python version to meet the version requirement. Installing Jupyter AI can be time consuming and tricky, so you can skip it and use language models (e.g. ChatGPT) outside the Jupyter environment. If you want to give it a try, before you start you need to check jupyter-ai documentation for requirements and instructions.

7. Additional Information (optional)

GeoPandas for shapefiles (optional):

pip install geopandas contextily shapely adjustText

Specialized packages and plots (optional):

pip install windrose

Note: This will not replace a GIS software such as ArcGIS Pro or QMap, but it is useful for integrating GIS maps in your workflow.

Useful tips

Sometime you need to update your Python version, which you can do by creating a new environment. Here is how to upgrade from Python 3.11 to 3.12:

conda create -n py312 python=3.12

Activate the new environment to take priority when you start Python

conda activate py312

You can check your environments:

conda info --envs

Then you can install everything at once, but creating a requirements.txt file with the following content:

jupyterlab
pyarrow
pandas
matplotlib
numpy
lckr_jupyterlab_variableinspector
xarray
netCDF4
cartopy
scipy
seaborn
statsmodels
scikit-learn
shap
tensorflow
earthengine-api
geemap
copernicusmarine
dataretrieval
requests
jupyter-ai
langchain-openai
langchain-google-genai
geopandas
contextily
shapely
adjustText
windrose

Then install everything using:

pip install -r requirements.txt

Next steps

Now you have JupyterLab and Python installed , you can start with these: