Setting up a Python environment

We recommend installing the labscript suite (regular or developer mode) in a virtual environment. This helps sandbox the codebase without interfering with (or being interfered with) your system Python installation, or Python environments used for other purposes. Below we outline how to create and activate a virtual environment for Anaconda Python and other CPython distributions (which we call ‘Regular’ Python here).

Anaconda Python

Anaconda Python includes a virtual environment manager as part of the conda executable. Here’s an example (on Windows):

Note

Make sure you have opened the Anaconda Prompt on Windows (available from the Start menu). conda is not available from the standard terminal by default. Launching ‘Anaconda Prompt’ will activate the base conda environment.

Warning

We do not recommend using the base conda environment for any project (labscript suite or otherwise). Working in a separate conda environment ensures any package resolution or update errors (however unlikely) are limited to that environment, and base is not compromised.

Quickstart

(base) C:\> conda create -n py38 python=3.8
(base) C:\> conda activate py38
(py38) C:\>

Once activated, the name of the virtual environment (in this case, py38 ) will prefix the command line.

Detailed Instructions

  1. Create a virtual (conda) environment. Here we name it py38 and ask conda to use Python 3.8 within the virtual environment (name and Python version are variable but these are conventional choices):

(base) C:\> conda create -n py38 python=3.8
  1. Activate the virtual (conda) environment:

(base) C:\> conda activate py38
(py38) C:\>

Regular Python

There are a number of ways to configure a virtual environment. If you are unfamiliar with doing so, we recommend using the venv module, part of the Python Standard Library. Here’s an example (on Windows):

Quickstart

C:\Users\wkheisenberg> mkdir labscript-suite
C:\Users\wkheisenberg> cd labscript-suite
C:\Users\wkheisenberg\labscript-suite> python -m venv .venv
C:\Users\wkheisenberg\labscript-suite> .venv\Scripts\activate
(.venv) C:\Users\wkheisenberg\labscript-suite> python -m pip install --upgrade pip setuptools wheel

Once activated, the name of the virtual environment (in this case, .venv ) will prefix the command line.

Detailed Instructions

  1. From a new terminal, create a directory for the virtual environment and enter it. Here we use a directory named labscript-suite in the user’s home directory, also the location of the labscript suite profile directory. You need create the virtual environment here, but it is a convenient choice.

C:\Users\wkheisenberg> mkdir labscript-suite
C:\Users\wkheisenberg> cd labscript-suite
  1. Create a virtual environment. Here we name it .venv, located inside the labscript suite profile directory.

C:\Users\wkheisenberg\labscript-suite> python -m venv .venv
  1. Activate the virtual environment:

C:\Users\wkheisenberg\labscript-suite> .venv\Scripts\activate

Note

This step is OS specific, e.g. on Linux it’s source .venv/bin/activate.

  1. Update the Python package installer and other installation packages of your virtual environment.

(.venv) C:\Users\wkheisenberg\labscript-suite> python -m pip install --upgrade pip setuptools wheel

Choosing an installation method

Once you have a virtual environment up and running, choose from one of the following 4 installation methods:

  1. Regular installation (Python Package Index);

  2. Regular installation (Anaconda Cloud);

  3. Developer installation (Python Package Index); or

  4. Developer installation (Anaconda Cloud).