Python virtualenv setup

Python "virtual environments" allow us to create isolated spaces, ensuring that each python project can have its own set of dependencies, without affecting other projects.

In other words, a virtual environment is a directory containing a few scripts that enable us to create a project-specific Python runtime environment, where using the pip install command will have effect only on the project itself, and not on other projects or on the system as a whole.


using Virtualenv is not strictly necessary for developing bots and integration with the Teamwire SDK, but we believe it can be useful to avoid dependency conflicts across different projects

The following sections will guide you through the steps involved in setting up Virtualenv for your Python environment.

Installing virtualenv

In order to install Virtualenv, we need to use the pip install command. Depending on your system and your python setup, you might need to invoke pip3 instead of pip. On Unix systems (e.g. Linux, MacOS X), you migh also need to use sudo to run commands as an administrator. Similarly, on Windows you might need to run the command prompt shell as an administrator.

$ [sudo] pip install virtualenv

If the installation succeeds, you can ensure that virtualenv is working with the following:

$ virtualenv --version

Creating a virtualenv

As mentioned, Virtualenv works on a "per project" basis, so let's suppose we have a project named "my_teamwire_bot" and we want to use Virtualenv with it.

Supposing the my_teamwire_bot directory already exists, we should first create a Python virtual environment for it with the following:

$ cd my_teamwire_bot
$ virtualenv <virtualenv_name>

in particular, <virtualenv_name> is usually env, so we simply issue that command as:

$ virtualenv env

This will create an env directory under the my_teamwire_bot

Activating the virtualenv

Once the virtual environment has been created, we should activate it, to ensure that we use isolated dependencies for our project.

Supposing we are still in the my_teamwire_bot directory, we activate the virtual environment with:

On unixes

$ source env/bin/activate

On Windows

> env\Scripts\activate.bat

The shell prompt will change, showing the environment name, like the following:

On unixes

(env) me@my-machine:~/my_teamwire_bot#

On Windows

(env) C:\Users\me\Documents\my_teamwire_bot>

From now on, every time you will issue a pip install command, this will only affect the activated project.


Installing the Teamwire SDK in an isolated virtual environment related to you project you simply have to run

$ pip install /path/to/sdk/teamwire_api-1.6.0-py39-none-any.whl

Dectivating the virtualenv

Once finished working on a specific project, you can deactivate its virtual environment. This can be done with the deactivate command, which is available only if a Virtualenv is currently activated:

$ deactivate