Using External Python Interpreter in Squish 6.5 and Earlier

Last edited on

Script Solution

See the article Changing Python Interpreter in Squish 6.6 . The script provided there also works for earlier versions of Squish.

Introduction

Depending on the operating system, froglogic’s Squish binary packages either bundle a Python interpreter or use a Python interpreter provided by the operating system.

Python versions used by Squish binary packages:

Operating SystemPython version
LinuxPython 2.7.x (bundled, SQUISHDIR/python)
Mac OS XMac OS X’s default Python 2.7.x installation (depending on Squish binary package configuration)
WindowsPython 2.7.x (bundled, SQUISHDIR\python)

Changing the Python version used by Squish binary packages

⚠️ If you want to use a more recent version of Python than the one bundled with Squish, and are using Linux or Windows, please contact Squish support since we may be able to provide a Squish binary package with the version of Python you want.

Requirements

R: /home/myuser/squish-…/lib/_squishrunner: symbol lookup error: /home/myuser/squish-…/lib/libsquishinterpreter.so: undefined symbol: PyUnicodeUCS2_GetDefaultEncoding

R: /home/myuser/squish-…/lib/_squishrunner: symbol lookup error: /home/myuser/squish-…/lib/libsquishinterpreter.so: undefined symbol: PyUnicodeUCS2_FromUnicode

To test for UCS-2 and UCS-4 execute the following in the respective Python installation:

import sys; u = 'UCS-2 (2 byte Unicode)' if sys.maxunicode == 65535 else 'UCS-4 (4 byte Unicode)'; print 'This Python uses', u
Execute in Python:
python -c "import sys; u = 'UCS-2 (2 byte Unicode)' if sys.maxunicode == 65535 else 'UCS-4 (4 byte Unicode)'; print 'This Python uses', u"
Execute in cmd.exe or a shell:

Changing the Python installation used by Squish binary packages

You can change which Python installation a Squish binary package is using by adjusting the path of the Python installation to be used by Squish binary packages. This information is stored in the file SQUISHDIR/etc/paths.ini.

On Linux

Change the highlighted parts shown below in the SQUISHDIR/etc/paths.ini file’s LibraryPath and Scripting/PythonHome entries from…

LibraryPath = “@(SQUISH_PREFIX)/lib:@(SQUISH_PREFIX)/tcl/lib:@(SQUISH_PREFIX)/python/lib:@(SQUISH_PREFIX)/perl/lib/5.8.8/x86_64-linux/CORE:@(SQUISH_PREFIX)/ruby/lib”

Scripting/PythonHome = “@(SQUISH_PREFIX)/python

…to…

LibraryPath = “@(SQUISH_PREFIX)/lib:@(SQUISH_PREFIX)/tcl/lib:MY_PYTHON_LIB:@(SQUISH_PREFIX)/perl/lib/5.8.8/x86_64-linux/CORE:@(SQUISH_PREFIX)/ruby/lib”

Scripting/PythonHome = “MY_PYTHON

MY_PYTHON_LIB stands for the parent directory of the “lib” folder that contains the “python2.x” folder, typically /usr on Linux systems.

MY_PYTHON stands for the parent directory of the “bin” folder that contains the “python” binary or link, typically "/usr" (because /usr/bin contains the “python” binary or link) on Linux systems.

You can execute this Python code with the desired Python installation to obtain the values of MY_PYTHON and MY_PYTHON_LIB, too:

python3 -c "import os.path, sys; print(); print('MY_PYTHON_LIB: %s' % os.path.dirname(os.path.dirname(os.path.dirname(os.path.__file__)))); print('MY_PYTHON    : %s' % os.path.dirname(os.path.dirname(sys.executable)))"
Execute with desired Python installation:

Please note that in this command “python3” must be replaced accordingly.

On Mac OS X 10.9 and higher

You can use the install_name_tool command line tool to change the squishrunner to use Python 2.7. The install_name_tool is part of the command line developer tools and Xcode.

If you don’t have the command line developer tools or Xcode installed, you have to install it first. For this, please open Terminal.app and simply enter install_name_tool - this opens a dialog that let you choose to install the command line developer tools or Xcode.

You can then change the squishrunner to use Python 2.7. For this, please open Terminal.app and enter the following:

cd "<SQUISH_DIR>"

install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.5/Python /System/Library/Frameworks/Python.framework/Versions/2.7/Python lib/libsquishpython.dylib
In Terminal.app

(Replace <SQUISH_DIR> accordingly.)

Change the highlighted parts shown below in the SQUISHDIR/etc/paths.ini file’s LibraryPath entry from…

LibraryPath = “…:/System/Library/Frameworks/Python.framework/Versions/2.5:…”

…to…

LibraryPath = “…:/System/Library/Frameworks/Python.framework/Versions/2.7:…”

…and the Scripting/PythonHome entry from…

Scripting/PythonHome = “/System/Library/Frameworks/Python.framework/Versions/2.5

…to…

Scripting/PythonHome = “/System/Library/Frameworks/Python.framework/Versions/2.7

This change may cause warnings such as the following to be displayed in the Runner/Server Log:

sys:1: RuntimeWarning: Python C API version mismatch for module test: This Python has API version 1013, module test has version 1012.

In our experience these warnings are harmless.

Now this copy of squishrunner is configured to use Python 2.7.

On Mac OS X prior to 10.9

Change the highlighted parts shown below in the SQUISHDIR/etc/paths.ini file’s LibraryPath entry from…

LibraryPath = “…:/System/Library/Frameworks/Python.framework/Versions/2.5:…”

…to…

LibraryPath = “…:/System/Library/Frameworks/Python.framework/Versions/2.7:…”

This change may cause warnings such as the following to be displayed in the Runner/Server Log:

sys:1: RuntimeWarning: Python C API version mismatch for module test: This Python has API version 1013, module test has version 1012.

In our experience these warnings are harmless.

On Windows

Step 1: Change the highlighted parts shown below in the SQUISHDIR\etc\paths.ini file’s LibraryPath and Scripting/PythonHome entries from…

LibraryPath = “@(SQUISH_PREFIX)/bin;@(SQUISH_PREFIX)/tcl/bin;@(SQUISH_PREFIX)/****python;@(SQUISH_PREFIX)/perl/bin;@(SQUISH_PREFIX)/ruby/bin”

Scripting/PythonHome = “@(SQUISH_PREFIX)/****python

…to…

LibraryPath = “@(SQUISH_PREFIX)/bin;@(SQUISH_PREFIX)/tcl/bin;MY_PYTHON;@(SQUISH_PREFIX)/perl/bin”

Scripting/PythonHome = “MY_PYTHON

Here MY_PYTHON must be replaced with the appropriate path to your Python installation — for example, C:/****Python27 (use forward slashes or double backslashes)

Step 2: Rename…

SQUISH_DIR/lib/python*.dll

…to…

SQUISH_DIR/lib/python*_off.dll

Step 3: Copy…

python*.dll

…from your separate Python installation into…

SQUISH_DIR/lib