Errors when setting up a Python Virtual Environment with Squish

Last edited on

This assumes you have used the blog article Setting Up a Python Virtual Environment with Squish to set up Squish with your Python Virtual Environment.

No module named ‘encoding’ and similar import errors

You may get an error similar to

ImportError: No module named ‘encoding’


ImportError: No module named ‘_ctypes’

when starting a Python testcase in squishrunner. If you are using virtualenv version 20 and above, the virtual environment will not copy libraries from the source Python installation. As the squishrunner does not activate the virtual env, paths to the libraries of the source Python are not set.

In most cases this is solved by setting the PYTHONPATH environment variable for your IDE or squishrunner to include both the libraries folder of the source Python and the site-packages folder of your virtual env. Windows example:

set PYTHONPATH=**<SOURCE PYTHON>**\Lib;**<PYTHON VIRTUAL ENV>**\Lib\site-packages

… start squishrunner or IDE …