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
$ pip install virtualenv $ virtualenv -p <PYTHON_BINARY> <PYTHON_VENV_PATH>
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.)
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
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.