Products | Versions |
---|---|
Spotfire Statistica | 13.3.1 and higher |
When using the Python node in a workspace, instead of copying Python modules to the Python Lib folder, the end user may import the module as a custom library.
For example, Atest.py, attached to this knowledge base article below, cannot be used unless either copied to the Python Lib folder or by importing the path to the Python module. The Atest.py is a simple function that multiplies the input by 2. Copying to the Python Lib folder is not necessary, instead import the Python module path so that it is accessible.
To import the path so the Python module can be accessed, insert the following two lines:
import sys
sys.path.insert(0, 'C:/<location of the Python module>/') #make sure to use the forward slash here and not the backward slash
In the example, the follow lines are in the Python node:
import sys
sys.path.insert(0, 'C:/tmp/') #make sure to use the forward slash here and not the backward slash
import Atest
print (Atest.testFunc(1))
Note: Without importing the module, the Atest.py module would need to be copied to the Lib file. For Python 3.6, typical location is C:\Program Files\Python36\Lib.