Using Python Virtual Environments in Squish

Last edited on



Introduction

This article demonstrates how to set up a Python virtual environment using the virtualenv module, and how to use that virtual environment with Squish.


Linux

The steps below assume the following:

Respective values used below need to be adjusted to your specific setup.

Step 1 - Install virtualenv module

In a shell/terminal execute:

sudo pip3 install virtualenv

Step 2 - Create Python Virtual Environment

In a shell/terminal execute:

virtualenv -p /usr/bin/python38 /home/myuser/venv

Step 3 - Configure Squish to use external Python Installation

Configure Squish to use the desired external Python installation via PythonChanger.py :

In a shell/terminal execute:

cd "squish_dir"

/usr/bin/python38 /home/myuser/Downloads/PythonChanger.py

Step 4 - Configure Squish to use Virtual Environment

In the file squish_dir/etc/paths.ini change...

LibraryPath = "...:/usr/lib:..."

...to...

LibraryPath = "...:/home/myuser/venv/bin:..."

And also change...

Scripting/PythonHome = "/usr"

...to...

Scripting/PythonHome = "/home/myuser/venv"

Step 5 - Start Squish IDE / squishrunner

Start Squish IDE / squishrunner with a specific PYTHONPATH (execute in a shell/terminal execute; use a shell script for convenience):

PYTHONPATH=/usr/lib/python3.8:/usr/lib/python3.8/lib-dynload:/home/myuser/venv/lib/python3.8/site-packages "squish_dir/squishide"


Windows

The steps below assume the following:

Respective values used below need to be adjusted to your specific setup.

Step 1 - Install virtualenv module

In cmd.exe/Command Prompt execute:

pip install virtualenv

Step 2 - Create Python Virtual Environment

In cmd.exe/Command Prompt execute:

virtualenv.exe -p C:\Users\myuser\AppData\Local\Programs\Python\Python38\python.exe venv

Step 3 - Configure Squish to use external Python Installation

Configure Squish to use the desired external Python installation via PythonChanger.py :

In cmd.exe/Command Prompt execute:

cd "squish_dir"

C:\Users\myuser\AppData\Local\Programs\Python\Python38\python.exe C:\Users\myuser\Downloads\PythonChanger.py

Step 4 - Configure Squish to use Virtual Environment

In the file squish_dir/etc/paths.ini change...

LibraryPath = "...:C:\Users\myuser\AppData\Local\Programs\Python\Python38:..."

...to...

LibraryPath = "...:C:\Users\myuser\tmp\venv\Scripts:..."

And also change...

Scripting/PythonHome = "C:\Users\myuser\AppData\Local\Programs\Python\Python38"

...to...

Scripting/PythonHome = "C:\Users\myuser\tmp\venv"

Step 5 - Start Squish IDE / squishrunner

Start Squish IDE / squishrunner with a specific PYTHONPATH (execute in cmd.exe/Command Prompt; for convenience create a .bat file):

set PYTHONPATH=C:\Users\myuser\AppData\Local\Programs\Python\Python38\Lib;C:\Users\myuser\AppData\Local\Programs\Python\Python38\DLLs;C:\Users\myuser\tmp\venv\Lib\site-packages

"squish_dir\squishide.exe"