Support Forum

python macros don't work at all



Thursday 2nd February 2023
I'm running Layout, full version 20210519, on RHEL 8.4. Trying to run any sort of python macro, so I pop up the built-in macro editor and enter import LayoutScript from LayoutScript import * Then the execute button generates 1 Syntax error. (row 3) 1 Executing abort. So this installation is missing something basic. PYTHONPATH and PYTHONHOME are undefined. Do they need to be set to something? Python-3 is installed on the linux system. Do I need an alias?
Jürgen
LayoutEditorFull
Thursday 2nd February 2023
I guess that is a file name issue. The integrated editor supports macros in a C++ style and Python. I guess your macro is tried to be executed as C++ script. Please rename it with an extension *.py* and avoid the keyword *layout* in the first line. Then it should be executed with Python instead of the build-in C++ layout-script macro.
Jürgen
LayoutEditorFull
Thursday 2nd February 2023
By the way you will find a set of example macros within the layout folder under macros/examples. On Linux this folder is located under* /opt/layout/macros/examples*


Thursday 2nd February 2023
Yes that was the problem. Thank you. Next problem: getting python macros to work from a command line. Command line python works after setting the pythonpath: export PYTHONPATH=/opt/layout/python
Jürgen
LayoutEditorFull
Thursday 2nd February 2023
Yes, starting python from command line may need some environment to be set: PYTHONPATH, PYTHONHOME, and LD_LIBRARY_PATH could be required. The correct value you may get by reading these values from Python when triggered from the integrated editor. Some of the values (like /opt/layout/oa/lib/linux....) will just be needed if OpenAccess file format is used.