PythonPath
Synopsis
[config] PythonPath=directory
directory is one or more paths to valid directories. The maximum length for PythonPath is 1024 characters. By default, no directories are listed.
Description
When importing modules, Embedded Python uses the sys.path variable to determine the locations where Python packages may be located. PythonPath specifies additional directories where you plan to install Python packages, so that Embedded Python can find them when you want to import a module.
You may specify multiple directories. On Windows, separate multiple directories using a semicolon; on other platforms, use a colon to separate multiple directories.
Example
On Ubuntu, PythonPath=/libraries/mypackages:/libraries/morepackages adds two directories to sys.path.
The example below, from Terminal, shows that the specified directories are present in sys.path when Embedded Python is launched.
USER>do ##class(%SYS.Python).Shell()
Python 3.10.13 (main, Aug 25 2023, 13:20:03) [GCC 9.4.0] on linux
Type quit() or Ctrl-D to exit this shell.
>>> import sys
>>> sys.path
['/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload',
'/InterSystems/IRIS/lib/python', '/InterSystems/IRIS/mgr/python', '/libraries/mypackages',
'/libraries/morepackages', '/bin/local/lib/python3.10/dist-packages', '/bin/lib/python3/dist-packages',
'/bin/lib/python3.10/dist-packages']
Changing This Parameter
On the Advanced Memory page of the Management Portal (System Administration > Configuration > Additional Settings > Advanced Memory), in the PythonPath row, select Edit. Enter one or more directories.
Instead of using the Management Portal, you can change PythonPath in the Config.configOpens in a new tab class (as described in the class reference) or by editing the CPF in a text editor (as described in Editing the Active CPF).
When you edit this setting, it takes effect immediately. The new path is used for any new processes.