Installation of Python
How to start doing GIS with Python on a computer?
Well, first you need to install Python and necessary Python modules that are used to perform various GIS-tasks. The purpose of this page is to help you out installing Python and all those modules into your own computer. Even though it is possible to install Python from their homepage, we highly recommend using modern Python environment management and package installation system based on Conda-Forge.
Conda-Forge is a community-led collection of recipes, build infrastructure and distributions for the conda package management system. It is not a static distribution, but rather a continually updated set of packages, which provides open source distribution of the Python, R, and even Julia programming language packages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. In short, it makes life much easier when installing new tools on your Python to play with.
Conda-Forge is platform-agnostic and provides packages for Linux, macOS and Windows systems. These packages may be installed with the command conda install PACKAGENAME
or mamba install PACKAGENAME
(see below).
There are nowadays 2-3 major ways to access the conda-forge ecosystem:
- Anaconda is a full distribution of the conda-forge ecosystem, and includes Python, the conda package manager, and many other useful packages.
- Miniconda is a smaller distribution that includes Python and the conda package manager and is quite light-weight.
- Micromamba is a drop-in replacement for the conda package manager, but with much faster package installation speed.
In this course, we will use Micromamba to install our Python environment!
But we will synonymously use the term conda
environment to refer to the Python environments, be they managed with micromamba
, conda
, or mamba
.
Windows
To install the Micromamba utility, we will run a few lines of script in the Windows PowerShell. Earlier tutorials often show the use of the older CMD
Windows commandline, the current versions of Windows Powershell are already good to work with.
Please open the Windows PowerShell by typing Powershell
in the “Search” field of the taskbar. Copy, then paste and run the following commands:
Invoke-Webrequest -URI https://micro.mamba.pm/api/micromamba/win-64/latest -OutFile micromamba.tar.bz2
.tar.bz2
tar xf micromamba
.\micromamba.exe --help
The above code downloads the latest version of Micromamba and extracts it to the current directory. The last line checks if was successful and should list the help information of the micromamba
tool.
The next snippet will initialize the shell environment for the micromamba
tool and sets the folder where the Python packages for your Python environments will be stored (e.g. C:\Users\kmoch\micromamba
). This way, you can use and update your Python without needing administrator rights.
# We use our own home folder e.g C:\Users\kmoch\micromamba as the so called base prefix
$Env:MAMBA_ROOT_PREFIX="$($env:USERPROFILE)\micromamba"
# initialize the shell
.\micromamba.exe shell init -s powershell -p "$($env:USERPROFILE)\micromamba"
The last snippet will add the micromamba
tool to the PATH
environment variable and place it under, e.g. C:\Users\kmoch\Library\bin
. This will allow you to use micromamba
directly from the commandline in the future.
function Add-Path($Path) {
$Path = [Environment]::GetEnvironmentVariable("PATH", "User") + [IO.Path]::PathSeparator + $Path
[Environment]::SetEnvironmentVariable( "Path", $Path, "User" )
}
# and use micromamba directly
-Path("$($env:USERPROFILE)\Library\bin")
Add
# or MOVE
# MOVE -Force micromamba.exe Library\bin\micromamba.exe
COPY Library\bin\micromamba.exe micromamba.exe
MacOS or Linux
On MacOSX you can install Micromamba from homebrew
brew install micromamba
# Initialize shell configuration if necessary (ZSH is now MacOSX default):
./micromamba shell init -s zsh -p ~/micromamba
source ~/.zshrc
On Linux you can install Micromamba from the commandline:
# Linux/Bash Intel (x86_64):
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
# Initialize shell configuration:
./bin/micromamba shell init -s bash -p ~/micromamba # this writes to your .bashrc file
# sourcing the bashrc file incorporates the changes into the running session.
# better yet, restart your terminal!
source ~/.bashrc
For more backround, please read the manual: https://mamba.readthedocs.io/en/latest/micromamba-installation.html