Skip to main content
Software development for researchers

Python environment

Table of contents

Installing python

MacOS

On MacOS python comes pre-installed but its usually a good idea to also have a system-package manager installed such as

See also Using Python on macOS for more information.

Linux

Congratulations! You are already done.

Windows

To minimize the amount of pain while developing on Windows I recommend using the Windows Subsystem for Linux. Following the instructions there you can pretty much install any Linux you would like, such as Arch or Ubuntu.

You can then either edit the files directly inside the Linux using e.g. vim or nvim or you can open the files in Windows using your preferred editor. You can also couple your VSCode to WSL and edit and develop this way. This is probably the preferred option if you absolutely need to use Windows and already know VSCode and do not want to learn vim.

Basic Python environment

  1. Install an editor you like or use the one you already have.
  2. Use venv to create new environments.
1
python -m venv /path/to/new/virtual/environment
  1. To activate the environment (this makes sure pip, python and your $PATH points to the correct places) use the correct command according to your shell.

POSIX

Shell Command
bash/zsh source <venv>/bin/activate
fish source <venv>/bin/activate.fish
csh/tcsh source <venv>/bin/activate.csh
pwsh <venv>\Scripts\Activate.ps1

Windows

Shell Command
cmd.exe <venv>\Scripts\activate.bat
PowerShell <venv>\Scripts\Activate.ps1

To test what the activation does, first activate the environment, then type which python and pip --version. Then deactivate and try again. You will see that the paths have changed and probably pip is not even an available command any more.

  1. Then use pip to install packages.
1
pip install numpy
  1. Use python your_stuff.py to run code.
  2. Use deactivate to exit the environment.

Multiple python version

  1. Install uv to manage python versions.
  2. Create a new environment with (where X is the desired python version, skip --python to use default).
1
uv venv --python 3.X --seed /path/to/new/virtual/environment
  1. Activate like before.
  2. Install new python versions with uv python install 3.X.

Read the uv docs for more info.

To top
× Zoomed Image