Setting Up a Python Virtual Environment with Squish

Setting Up a Python Virtual Environment with Squish

Python Virtual Environments are great tools for separating different Python configurations on the same machine. Configuring Squish to use a virtual environment gives you the freedom to install packages and make changes that aid your testing efforts without compromising your existing Python installation(s).

Here we will show you how to set up a virtual environment using the virtualenv package and configure Squish to use it. Make sure that you have pip installed and that your Python and the Python shipped with Squish match. (You can ask our support staff to prepare binary Squish editions with Python 3 if needed.)

Creating the Virtual Environment

Install the virtualenv package, and create your virtual environment. Be sure to specify the Python that is used as source with -p.

$ pip install virtualenv

Warning: Moving the created folder to another location will break the activation script! (To fix it, you can run $ virtualenv --relocatable <PYTHON_VENV_PATH> and correct the VIRTUAL_ENV path in the activation script.)

Configuring Squish

After the virtual environment is created, configure Squish to use it by altering the paths.ini in <SQUISHDIR>/etc/.

In LibraryPath change @(SQUISH_PREFIX)/python to <PYTHON_VENV_PATH>/bin
(<PYTHON_VENV_PATH>/Scripts on Windows).
Set Scripting/PythonHome to "<PYTHON_VENV_PATH>".

For Windows: Rename <SQUISH_DIR>/lib/python*.dll to <SQUISH_DIR>/lib/python*_off.dll and copy your python*.dll from your separate Python installation into <SQUISH_DIR>/lib.

There are more detailed instructions on how to change the Python installation of Squish here.


We can test our Python virtual environment with the following Squish test script:

import numpy
def main():
    test.passes("numpy was found")

Pick any module that is not present in your global and/or Squish Python installation(s). (Here we’ll use numpy.) Then, activate your virtual environment, and install the module:

(Linux)   $ source /bin/activate
(Windows) $ .\\Scripts\activate.bat
$ pip install numpy
$ deactivate

Running the above test script with Squish should result in a PASS containing a “numpy was found” message. Now you should be good to go!

Since joining froglogic as a developer in 2017, he's been mostly tinkering with Qt, Python and web technologies. His free time is consumed by playing Dungeons&Dragons with his friends and trying out the latest in VR gaming.


Leave a reply

电子邮件地址不会被公开。 必填项已用*标注