Skip to content

Instantly share code, notes, and snippets.

@mcvella
Last active September 28, 2023 18:14
Show Gist options
  • Save mcvella/1e9f33e01fe020becf2dc9b5ffcea9f9 to your computer and use it in GitHub Desktop.
Save mcvella/1e9f33e01fe020becf2dc9b5ffcea9f9 to your computer and use it in GitHub Desktop.
Viam Python venv

Viam + Python

This guide will help you get set up with Viam with Python. It assumes that you are starting from scratch, and will walk you through setting up a fresh environment and installing the necessary requirements.

Setup your project

The first step is to create a directory to house your project. For this guide, we will be using the directory name viam-python:

mkdir viam-python
cd viam-python

Create a Virtual Environment

Now that we are in the project directory, let's create and activate a virtual environment for python to run in.

INFO Creating a virtual environment (venv) is important as it isolates this python environment from any other you might already have. This allows us to ensure a clean project and easier dependency management, as well so not bloating your global python environment.

sudo apt-get install -qqy python3-venv
python3 -m venv viam-env
source viam-env/bin/activate

You will now see (viam-env) prepend the commands in your terminal window. This shows that the python packages being uses are from this particular environment.

You can exit this environment by running deactivate.

Install Viam

Inside the activated viam-env python environment, you can now install the Viam SDK:

pip3 install viam-sdk

This will install Viam and all required dependencies.

Should you need to install your own requirements, be sure to do so in this environment.

Setup your IDE

You'll now want to point your IDE to use the python interpreter of your new environment, rather than the default interpreter (likely the global python interpreter).

The following steps are for VS Code. If you're not using VS Code, please read your IDE's documentation on selecting python interpreters.

  1. Open the viam-python directory in VS Code
  2. Open the Command Palette (using ⇧⌘P or through the menus View -> Command Palette)
  3. Select the command Python: Select Interpreter. There, you should see all the interpreters available to you. You're looking for one the on you just made: viam-env. It will look something like: Python 3.11.5 ('viam-env': venv) ./viam-env/bin/python. If you don't see it, click the Refresh icon on the top right of the Command Palette.

Your IDE will now recognize all packages installed in this environment.

Start building!

You are now ready to start using Viam's Python SDK!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment