froglogic / Blog / Tip of the Week / 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!


If you encounter any problems, please take a look at the following knowledge base article: Errors when setting up a Python Virtual Environment with Squish.



Some have pointed out that the original tutorial did not work for them. Python virtual environments created from the ‘venv’ module were missing some dependencies used by Squish. I’ve revised the instructions, switching from the ‘venv’ module to the ‘virtualenv’ package, which also works for Python 2, not only 3.

Thanks to everyone for providing useful feedback!

I am stuck with this error message:, 2): Library not loaded: @rpath/libpython3.7m.dylib
I did all the changes specified in this tutorial but does not change anything.
The only way to make it work is to change it via install_name_tool on osx or put the lib in the /usr/local/lib folder.
Why do we need a Framework installation for using Squish? That is a bit of an overhead I think (but maybe required, I don’t know)
Also wondering if I will have some issues on windows too…

    Using install_name_tool to change the library path of the squishtest module to the Python from which your virtualenv originated is the correct way to do it. This tutorial is only concerned with Python virtual environments used directly with Squish (aka. test scripts that are run via squishrunner). You can always contact our support if you run into further problems.
    Best regards!

Leave a Reply

Your email address will not be published. Required fields are marked *

Copy link
Powered by Social Snap