Python (Installation)#

“The zen of thriving Python projects in 2025 is one interpreter per project and one tool‑chain per task. Master virtual environments first; the rest follows naturally.”

Python 2 reached end‑of‑life in January 2020 and is no longer shipped by mainstream Linux distributions or Windows installers. Today every actively maintained package—scientific, geospatial, or otherwise—supports CPython ≥ 3.9, with most libraries now testing against Python 3.13. Multiple interpreters can still coexist on the same machine (QGIS / ArcGIS Pro embeds its own 3.11, Nvidia CUDA ships one for PyTorch, etc.), but the modern way to insulate projects is through lightweight virtual environments created by venv, pipx, or conda/mamba.

This chapter distils a workflow that reliably builds the computational stack used throughout this e‑book, regardless of platform. It emphasises

  • pip + venv on Linux/macOS (preferred),

  • conda/mamba on Windows or when you need complex compiled dependencies,

  • recent improvements in binary wheels for GDAL/Fiona/Shapely (pip on Windows is finally painless!), and

  • sustainable ways to keep environments reproducible.


Installing extra packages with pip#

More than 500 000 projects live on PyPI today. Basic syntax:

(vflussenv) $ pip install seaborn

(flussen v) > pip install seaborn

Note

Do not use the --user flag inside a virtual or conda environment; it bypasses the environment and pollutes your home directory.

Bulk install#

E‑book examples rely on the following scientific stack (already included in the provided requirements.txt):

  • numpy, pandas, scipy, matplotlib, seaborn

  • geopandas, shapely, rasterio, rasterstats, laspy

  • networkx, openpyxl, tabulate

Install them manually with:

(vflussenv) pip install numpy pandas geopandas rasterio rasterstats laspy networkx openpyxl tabulate

Jupyter kernel#

(vflussenv) pip install ipykernel jupyterlab
(vflussenv) python -m ipykernel install --user --name vfluss_kernel

Select vfluss_kernel from Kernel > Change kernel inside JupyterLab.


Updating environments#

(vflussenv) pip install -U pip setuptools wheel
(vflussenv) pip list --outdated           # preview
(vflussenv) pip install -U "numpy>=2.3"  # upgrade selectively

Full upgrade:

pip freeze > requirements.txt             # pin current versions
sed -i 's/==/>=/' requirements.txt        # allow newer releases (Linux), or edit manually
pip install -r requirements.txt --upgrade

If pip reports ResolutionImpossible, relax or delete the offending version pins and rerun.


Using the environment in IDEs#

JupyterLab#

(vflussenv) jupyter lab

Point your browser to http://localhost:8888/lab. Switch kernels via the Kernel menu.

PyCharm#

  • File > Settings > Python Interpreter > Add > Existing > pick ~/venvs/vflussenv/bin/python (Linux) or %USERPROFILE%\mambaforge\envs\flussenv\python.exe (Windows).

  • Enable Sync Python packaging tools so that pip install inside PyCharm’s terminal updates the interpreter list.


Deleting environments#

  • venv: rm -rf ~/venvs/vflussenv

  • conda: conda env remove -n flussenv


Installation bottom line#

  • Use python -m venv (pipx for CLI tools) unless a package requires C/C++ libraries that your OS can’t satisfy—then reach for conda‑forge.

  • Windows users no longer need conda for GDAL, but conda remains the easiest path for a full geospatial data‑science stack.

  • Pin exact package versions for archival projects; use >= pins for living research code.

  • Never install packages with sudo pip; always work inside an isolated environment.