Skip to content

Installing Python

At your own computer

The instructions to install vary a bit based on which operating system you are using, but they are all essentially the same.

Install Python

On Mac or Linux, you probably already have python installed. You can check by opening a terminal and typing python (or python3 on some systems). Still, it might be a good idea to setup a Python installation which can handle different version of Python via uv or pyenv. On Windows, however it is a bit more complex.

Installing Python in Windows

NOTE: If you are running Windows 10 1905 or newer, you might need to disable the built-in Python launcher via Start > "Manage App Execution Aliases" and turning off the "App Installer" aliases for Python

You might have Python already installed, but we recommend that you install python via uv or pyenv-win, so that you will be able to use virtual environments with different Python versions should it be needed.

The installation instructions are available at the offical uv homepage. On most recent versions of Windows, packages can be installed via the terminal using winget:

winget install --id=astral-sh.uv  -e

After uv has been installed, you can use uv to install a specific python version, e.g. version 3.13: uv install python 3.13.

How should I get the uv project files in the right folder?

The easiest way to manage where the project should be, is to first create the folder in the file explorer where you want it. Then, in that folder, right-click on the empty space, and select "Open in terminal". This will open a terminal session at the folder location.

A good location is typically in C:\users\<user>\projects\<this-project-name>, typically accessible in the terminal (after creation) via

cd ~\projects\<this-project-name>

Then, you can go ahead and use uv from the terminal. E.g. to initialize a new empty project by running uv init.

Please note that uv is able to find uv instances further up in the file-tree. So, if you accidentally created a path in e.g C:\users\<user>\ (the default location when opening a terminal), then go ahead and remove all uv.lock and .venv files from that top-location.

Typically, it is good to initialize a uv controlled project by running uv init in the folder, which will create some necessary files. Then, to create a new virtual environment, use uv venv.

Packages can be added with uv add <packagename>, or with uv pip install <packagename>. To run a script with your environment, either activate the environment with uv venv and the run your script with python main.py, or directly with uv run main.py.

A neat thing about uv, is that it can auto setup your environment (if the necessary uv files are already in place, and packages have been installed with uv add), by directly running uv run main.py. This is makes it easy to share code with eachother and ensure that the python environment is identical.

We will copy some of the install instructions from the pyenv-win how to install GitHub page here below, but we refer to the offical install instructions should there be problems.

Installing via PowerShell

The easiest way to install pyenv-win is to run the following installation command in a PowerShell terminal:

Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"

If you are getting any UnauthorizedAccess error as below then start Windows PowerShell with the "Run as administrator" option and run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine, and then re-run the above installation command. Note that changing the execution policy could potentially lower the security of your system. If you want to check your current execution policy level, before changing to RemoteSigned run Get-ExecutionPolicy in the PowerShell window.

For more information on 'digitally signed' or 'Security warning' you can refer to following issue #332

Installation of pyenv is now complete! The next step is to set up Python.

Setup python

First, update the list of available python version:

pyenv update

Then list the available python versions:

pyenv install --list

Then, install a version of python (e.g. 3.13.1):

pyenv install 3.13.1

Then, set the python version as your current python version:

pyenv global 3.13.1
pyenv local 3.13.1

Optionally (recommended), set up a virtual environment by installing pipenv and then creating a pipenv environment (make sure to run the command from the folder to you want the virtual environment to be related to):

pip install pipenv
pipenv shell

Finally, upgrade/install essential packages for working with python packages:

pip install --upgrade pip setuptools wheel

This version of the install will allow you to use virtual environments, but you will not be able to use different versions of python.

First, install python from the Windows store. One way is to open a new terminal (Windows Terminal or powershell), and running python. This will either take you to the store or start python if python is already installed.

Setup paths: To be able to use all packages you install, you need to add the folder where the packages get installed to to your path. You can run the script below in a powershell window to find and add the path automatically:

$scriptPath = Get-ChildItem -Path $env:LOCALAPPDATA -Recurse -Filter "Scripts" -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -like "*PythonSoftwareFoundation*" } |
Select-Object -ExpandProperty FullName -First 1

if ($scriptPath) {
    [System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";$scriptPath", [System.EnvironmentVariableTarget]::User)
    "Scripts directory added to PATH: $scriptPath"
} else {
    "Scripts directory not found."
}

To check that it works, install pipenv and check that it works:

pip install pipenv
pipenv shell

This should now put you in a virtual environment. You can verify this by checking the path to python in the current shell:

python -c "import sys; print(sys.executable)"

You should get a path similar to C:\Users\<user>\.virtualenvs\<folder-name>-NpavKrNU\Scripts\python.exe

You can remove the created environment by running pipenv --rm. Close the shell.

Now, open a new terminal/powershell and naviate to the folder where you have/will have your script, and the run pipenv shell to create a virtual environment. Now you should be able to find the virtual environment in e.g. Visual Studio Code.

Setting up Python via uv on Linux/Mac

The installation instructions are available at the offical uv homepage. On Linux, you can often find uv with your standard package manager. Otherwise, or if using a Mac, uv can be installed via curl:

curl -LsSf https://astral.sh/uv/install.sh | sh

or via wget:

wget -qO- https://astral.sh/uv/install.sh | sh

After uv has been installed, you can use uv to install a specific python version, e.g. version 3.13: uv install python 3.13.

How should I get the uv project files in the right folder?

The easiest way to manage where the project should be, is to first create the folders where you want them to be using the terminal.

A good location is typically in ~/projects/<this-project-name>. To create this folder, with a project folder named sysbio-projectrun

mkdir -p ~/projects/sysbio-project

if you want to navigate to this folder later, use:

cd ~/projects/<this-project-name>

You can verify that you are in the correct folder by running:

pwd

Then, you can go ahead and use uv from the terminal. E.g. to initialize a new empty project by running uv init.

Please note that uv is able to find uv instances further up in the file-tree. So, if you accidentally created a path in e.g ~ (the home folder, default location when opening a terminal), then go ahead and remove all uv.lock and .venv files from that top-location.

On Mac if using the Finder to see the files, you might need to enable seeing the files on the drive, or use "go" and go to "Home" folder to get to the files. Do not put the files in an icloud folder, this will likely cause problems.

Typically, it is good to initialize a uv controlled project by running uv init in the folder, which will create some necessary files. Then, to create a new virtual environment, use uv venv.

Packages can be added with uv add <packagename>, or with uv pip install <packagename>. To run a script with your environment, either activate the environment with uv venv and the run your script with python main.py, or directly with uv run main.py.

A neat thing about uv, is that it can auto setup your environment (if the necessary uv files are already in place, and packages have been installed with uv add), by directly running uv run main.py. This is makes it easy to share code with eachother and ensure that the python environment is identical.

Additional setup if not using uv

Make sure that you have also pip installed:

pip install --upgrade pip

Note: on some versions of mac, we need to run using pip3 instead of pip and python3 instead of python:

pip3 install --upgrade pip 

Or potentially in the following way:

python3 -m pip install --upgrade pip

Installing a C-compiler

When doing modelling (e.g. in thesis works) it is possible to get much faster simulation by compiling the models to C-code. To do this you need to have a valid C-compiler. Below we offer some quick steps of installing a valid compiler on Windows, Linux or MacOS.

Windows

The full official Windows instructions are available here, but in short you can either install the smaller standalone compiler (Build Tools for Visual Studio 2022/2019), or the full version of visual studio. We recommend using the standalone compiler.

Standalone compiler (recommended)

On most modern Windows installations, you can download and install the compiler needed via winget. Open a powershell (or Windows terminal) shell and run

winget install Microsoft.VisualStudio.2022.Community --override "--wait --quiet --add ProductLang En-us --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended"

Note that the installation will take a long time without much feedback, so have patience. Also note that you will likely get a popup asking for elevated permissions.

Alternatively, you can download the Build Tools for Visual Studio 2022/2019 installer, and run it. Make sure to install Desktop development with C++ or alternatively the C++ build tools and ensure the latest versions of MSVCv143 - VS 2022 C++ x64/x86 build tools and Windows 10 SDK.

Full Visual Studio install (not tested)

Download the full version installer of Sisual Studio, make sure to install Python development, Python native development tools, and Windows SDK (which can be found under Native development).

Also, make sure that you install Desktop development with C++ and make sure that the latest verison of MSVC is checked. You might have to open the visual studio installer again and "modify" the installation to check if the compiler is installed.

If the installer doesn't detect your toolset version, Set $env:PlatformToolset before building.

Linux

You probably already have a compiler available, otherwise install e.g. gcc through your package manager.

MAC

Note: on Mac, python and pip are often called via python3 and pip3

To get a C-compiler, you need to install Xcode. Xcode is available in the Mac app store. After installation, start Xcode and agree to the license agreement.

It might also be possible to install gcc, e.g. by opening a terminal and typing gcc which should prompt a request for installing Command line developer tools.

At a computer in a LiU computer hall (Linux)

If you are at a LiU shared computer running Linux (such as in the SU halls, or when logged in via ThinLinc), python3 should already be available. You can test with:

python3 --version

To setup a virtual environment in the computer halls to be able to install packages, you should do:

python3 -m venv .venv
source .venv/bin/activate

Then you can run python as normal, and use pip. For example to update pip:

python -m pip install --upgrade pip

Google Colab

Google Colab is a service where you can run Python code on a remote server. This can be good to share examples and do some initial testing. However, you need to know that data/files are not being saved, and thus you need to save and download the data from somewhere else.