ImportError: cannot import name 'Qt' from 'pya' (/../lib/python3.8/site-packages/pya/__init__.py)

Does the above error mean that klayout was not compiled with Qt? I get it when doing:

import pya
from pya import Qt

which is used by some DRC/LVS scripts

I'm using klayout-0.29.10 installed with pip.

Comments

  •  ~/temp (master)$ python3 -m venv .venv
     ~/temp (master)$ source .venv/bin/activate
    (.venv) ~/temp (master)$ python3 -m pip install klayout
    Collecting klayout
      Using cached klayout-0.29.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.8 MB)
    Installing collected packages: klayout
    Successfully installed klayout-0.29.10
    (.venv)  ~/temp (master)$ python3
    Python 3.8.10 (default, Jul 29 2024, 17:02:10)
    [GCC 9.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pya
    >>> from pya import Qt
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: cannot import name 'Qt' from 'pya' (/home/mrg/temp/.venv/lib/python3.8/site-packages/pya/__init__.py)
    
  • Hi!

    I may be mistaken, but DRC/LVS scripts are written on Ruby.

    pya module is defined in KLayout 's built-in Python interpreter, so should be executed only there, not in standalone Python. See https://www.klayout.de/doc-qt5/code/index.html for list of things defined in pya module.

  • Hi,

    As @EugeneZelenko explained above, the Qt framework (subset) is a part of the KLayout main GUI program.

    If you want to use Qt with the KLayout standalone Python module, PyQt5 is a choice.
    You can find a simple example in this post.

  • Hello,

    I'm the one who wrote the pymacro for sky130 DRC/LVS that uses Qt.

    To clear things up, this is not using KLayout's standalone Python module, but uses KLayout's built-in Python interpreter. The purpose of using Qt before running the DRC is to have some options that can be toggled.

    Yes, DRC/LVS can only be executed from Ruby. Therefore, this Python script sets up a pya.Interpreter() to run DRC. This can be seen in this line: https://github.com/efabless/sky130_klayout_pdk/blob/9e3b9c05e1a09f1376eaa232a9db73dcb48d747b/tech/sky130/pymacros/run_drc_custom.lym#L122

    This works without any problems on my platform (Debian trixie). When executing the pymacro, a small window opens in which you can select which parts of the DRC should be activated, then the DRC is executed on the current layout.

    Of course, this won't work for the standalone Python module, as neither Qt nor Ruby scripts are supported.

    @mrg do you get the same error when you run the pymacro from the "Efabless sky130" menu?

  • Thanks for this discussion :)

    Point is, that DRC/LVS is pretty useless with the Python module alone as that not only misses Qt, but also does not feature Ruby, which is needed to execute DRC/LVS scripts. The typical runtime for that case is the KLayout binary in batch mode (klayout -b -r ...).

    I understand the popup is some UI integration thing, but the DRC/LVS can be run without UI in batch mode too. Right?

    Matthias

Sign In or Register to comment.