5. Setting up Jupyter Notebook
First,test that everything works
If you don't have the Powershell open, please open it. Powershell can be found by clicking on the Windows start menu button and start typing Powershell. MacOSX and Linux users should open theur default terminal window.
Also always make sure you have activated your geopython2025 environment.
(base) micromamba activate geopython2025
(geopython2025)You can test that the installations have worked by running following commands in a Python console. At first start the Python console:
(geopython2025) python
Type "help", "copyright", "credits" or "license" for more information.
>>>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import shapely
import fiona
import geopandas as gpd
import cartopy
import mapclassify
import rasterio
import rasterstats
try:
import gdal
except ImportError:
from osgeo import gdalIf you don't receive any errors, everything should be working!
In order to close the Python interpreter type exit() and press return/enter or press Ctrl+Z to exit.
Under Mac/Linux you might have to press Ctrl+D to exit.
(geopython2025) >>> exit()Proj database location info
Sometimes it happens that the Python/conda environment fails to configure the PROJ environment correctly. This can happen when mixing geospatial library installations from PyPI and conda-forge, or conflicting environment variables from other software, like Postgres/PostGIS.
A fairly robust way to keep working is to manually setting at least the environment variable PROJ_DATA. To do so, you’d start a Python REPL session (or in a notebook) and query the pyproj.datadir.get_data_dir(). Then, in all future sessions you set this path manually before loading any other geospatial libraries:
import os
import pyproj
# the confirming error appears [UserWarning: pyproj unable to set PROJ database path]
>>> /Users/akmoch/micromamba/envs/dggrid/lib/python3.10/site-packages/pyproj/network.py:59: UserWarning: pyproj unable to set PROJ database path.
# query the the path from a function
pyproj.datadir.get_data_dir()
>>> '/Users/akmoch/micromamba/envs/dggrid/lib/python3.10/site-packages/pyproj/proj_dir/share/proj'Then use this path to set the environment variable manually at the begin of new Python sessions/script:
import os
os.environ["PROJ_DATA"] = '/Users/akmoch/micromamba/envs/dggrid/lib/python3.10/site-packages/pyproj/proj_dir/share/proj'Your path my vary, adjust based on your environment.
Install IPykernel and start up Jupyter Notebook
The Jupyter Notebook server is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more. Jupyter Lab is an extended version that allows to have several notebooks open at the same time. We will be mostly working with Jupyter Lab.
Before we start Python coding we will make our newly created conda Python environment known to the Jupyter notebook system by installing the kernel, basically the execution engine link from Jupyter web notebook to our Python environment:
Make sure you are in your dedicated working directory, your "geopython2025" folder, on the Command line window (Powershell). And make sure the geopython2025 conda environment is activated:
(base) micromamba activate geopython2025
(geopython2025) python -m ipykernel install --user --name geopython2025That should be it. You should now be able to start the Jupyter notebook server:
(geopython2025) jupyter labThis should open a webpage in your default webbrowser.
Don't close the console window nor the browser window where the notebooks opened. Always use the "File" -> "Save and Checkpoint" and then -> "Close and Halt" menu options in the notebooks, and the "Quit" button on the main notebook server webpage.