Support Forum

ImportError: dynamic module does not define module export function (PyInit_LayoutScript)

surendran

Wednesday 8th March 2023
Traceback (most recent call last): File "C:/Users/name21/Desktop/example/sample.py", line 2, in <module> import LayoutScript ImportError: dynamic module does not define module export function (PyInit_LayoutScript) Hai, When I am trying to import a simple python script under edit macros in layout editor, I am facing the above error. I am not sure whether this is bug or something,
Jürgen
LayoutEditorFull
Wednesday 8th March 2023
In your case loading the LayoutEditor module into Python fails. This can have more than one reason. The most common reason on Windows is a Python version mismatch. There is next to the LayoutEditor package a second Python package installed and some port are loaded from the second Python package and some parts are loaded from the Python package shipped with the LayoutEditor. To avoid this, please start Python from the build in TextEditor and don't set any PYTHONPATH, etc variables on the system. Then the LayoutEditor will set anything correctly in a way that the LayoutEditor Python module will run. Another reason could be starting the layout.exe directly instead of the LayoutEditor.bat or start.bat. In that case the LayoutEditor binaries could not be found by Python.
surendran

Wednesday 8th March 2023
Attachments:
(only for registered users)

2.PNG


1_1.PNG

Now, To make sure of PYTHONPATH, I deleted already set path for my python (shown in attached pic 1_1). Then, I uninstalled layout editor and installed again. This time I installed the package (.msi) released before my expiry of maintenance period. Still, I am getting the same error as before, "ImportError: dynamic module does not define module export function (PyInit_LayoutScript)". Also, I noticed in the layout editor , under about open access, plug in paths were missing (shown in attached pic 2)
Jürgen
LayoutEditorFull
Wednesday 8th March 2023
PYTHONPATH is the setting used by Python to look for extension modules, While PATH is the setting where the system looks for binaries. Deleting the setting for PATH may break some installations on your system. You have installed PyCharm on your system. It comes with its own Python package. This Python package will most likely not work with the LayoutEditor extension. (unless both package are the exact same Python version). Please start Python with the -vvv option. Then Python will output additional information where it looks for its extension modules and you will get more information on the problem. To run the LayoutEditor with this additional information, please start it with the option *--debug*. Then this information will be output to the command line window it was started from.
surendran

Thursday 9th March 2023
Attachments:
(only for registered users)

3.PNG

I tried to use python 3.7 version (downloaded from python.org) and pycharm 3.7 version, trying to match with the LayoutEditor extension for the same python version. And the PATH (under user variables) was set automatically (as shown in attached pic 3) when I installed python 3.7 version (downloaded from python.org). Then, I tried to load python script under edit macros in layout editor, still I am facing the same error, "Traceback (most recent call last): File "C:/Users/name21/Desktop/example/sample.py", line 2, in <module> import LayoutScript ImportError: dynamic module does not define module export function (PyInit_LayoutScript)". As you mentioned, I didnt set any PYTHONPATH and just ran python script from layout text editor. Facing the same issue again. And, I couldnt get your last three lines in previous reply. Can you please let me know clearly further?
Jürgen
LayoutEditorFull
Thursday 9th March 2023
If you start python like: ```python.exe -vvv sample.py``` it will print out the folders where it looks for the LayoutScript module and its dependents files. One required file is not found. The output will tell you which one and where it was searched. You need to extend the search path with the correct location.