importing modules (running Windows 10, KLayout 0.27.8)

Hi all,

I'm encountering a slight issue with import statements in my python macros.
I think everything in the environment variables is OK. I have added to PYTHONPATH the macro directories, and
I haven't messed with KLAYOUT_PATH which seems to be some kind of internal environment variable I'm not even sure how to access.
Anyways, I have a few .py files in the Local directory for python macro development and when I import one of the files into another
and run that:

**import pya
import moduleupdater

layout = pya.Layout()
top = layout.create_cell("TOP")
l1 = layout.layer(1, 0)
top.shapes(l1).insert(pya.Box(0, 0, 1000, 2000))**

I get such an error message as below:

No module named 'moduleupdater'

In any other IDE you would not have this problem, so I am wondering if everything is properly set up and how to fix this.
Is there a special configuration for this in KLayout?



  • There is a common misunderstanding: KLayout is not a Python IDE.

    KLayout comes with it's own brand of Python and does not share modules with other installations such as Anaconda. Basically this is not possible as binary compatibility is not given - for example Anaconda is based on MSVC while the standalone KLayout app is based on gcc/MinGW + MSYS2. So even if you tweak the paths, you usually will not be able to simply plug in Python modules from other spaces. Thank Microsoft for not bundling their system with a decent compiler.

    If you need low-level features only you can go the other way round and use the klayout module available on PyPI inside Anaconda. This will not give you the GUI however.

    It is possible to build the KLayout application against Anaconda, but then KLayout will no longer be an independent binary. As KLayout technically is compatible with MSVC 2017 and 2019, it should be possible to create an Anaconda package for it. I do not want to support that deployment path myself however.

    The whole thing is a different story on Linux where KLayout utilizes the system Python. In that case, you can install packages in the system and they will be shared with KLayout.


Sign In or Register to comment.