Installing PythonΒΆ

Before you can use xdoctest, you must have Python installed. Its also best practice to be in a virtual environment. If you are a Python beginner, then I would recommend setting up a conda environment.

On Linux, I typically use this end-to-end script for installing conda, creating, and activating a virtual environment.

# Download the conda install script into a temporary directory
mkdir -p ~/tmp
cd ~/tmp

# To update to a newer version see:
# for updating
CONDA_GOT_SHA256=$(sha256sum $CONDA_INSTALL_SCRIPT | cut -d' ' -f1)
# For security, it is important to verify the hash
if [[ "$CONDA_GOT_SHA256" != "$CONDA_EXPECTED_SHA256_HASH" ]]; then
    echo "Downloaded file does not match hash! DO NOT CONTINUE!"
    exit 1;

# Install miniconda to user local directory
# Activate the basic conda environment
source $_CONDA_ROOT/etc/profile.d/
# Update the base and create a virtual environment named py38
conda update --name base conda --yes
conda create --name py38 python=3.8 --yes

# Activate your vitualenv
# I recommend doing something similar in your ~/.bashrc
source $_CONDA_ROOT/etc/profile.d/
conda activate py38

Once you have created this conda environment, I recommend adding the following lines to your .bashrc. This way you will automatically activate your virtual environment whenever you start a new bash shell.

# Enables the conda command
source $_CONDA_ROOT/etc/profile.d/

if [ -d "$HOME/.local/conda/envs/py38" ]; then
    # Always start in a virtual environment
    conda activate py38

For other operating systems, see the official documentation to install conda on Windows or on MacOS.

Once conda is installed the commands for managing conda virtual environments are roughly the same across platforms.