Guides

Python

The KINARM labs run on MATLAB but increasingly we are using Python to do our data analyses and computational modeling (e.g. MotorNet).

Here are some pointers to how to get going with Python, in particular virtual environments.

Install Python

On MacOS I like to install Python3 using the Homebrew package manager, like this:

brew install python3

Create a virtual environment

python3 -m venv my-venv

Activate a virtual environment

source my-venv/bin/activate

Install pip

pip is what we use to install packages so we need to install pip into our venv first:

python3 -m ensurepip

Install packages into a venv

For example to install numpy:

python3 -m pip install numpy

Snapshot all installed packages

python3 -m pip freeze > requirements.txt

This creates a file called requirements.txt that you can keep with your code, so that anyone can reproduce your entire python environment using venv (see below)

Install from a requirements.txt file

python3 -m pip install -r requirements.txt

Deactivate a venv:

deactivate