apparently "Typing" is not avalible

from __future__ import annotations
# some of these types are deprecated: https://www.python.org/dev/peps/pep-0585/
from typing import Protocol, Dict, List, Iterator, Tuple, TypeVar, Optional
T = TypeVar('T')

Comments

  • Okay.

    What is available strongly depends in the Python version your KLayout instance comes with. If you want to have a specific version with specific capabilities, you'll need to build KLayout against it.

    Another option is to use the klayout module from PyPI with your favorite Python. If you're happy with the database part it will be sufficient.

    Matthias

  • Matthias

    Thanks for the reply I am currently using Anaconda with python 3.8
    So how exactly do I use the PyPI module with klayout ?

    Another option is to use the klayout module from PyPI with your favorite Python. If you're happy with the database part it will be sufficient.

    Regards
    Tracy

  • Please try "pip install klayout".

    You can use "import klayout.db as pya" to get the "pya" namespace. But it will just provide you with the layout manipulation API.

    Matthias

  • Matthias

    Thanks this works for windows do I need too set a path or env variable?

    Tracy

  • Matthias,
    I have gotten this far and would like to load the following modules,
    many thanks for your help

    # some of these types are deprecated: https://www.python.org/dev/peps/pep-0585/
    from typing import Protocol, Dict, List, Iterator, Tuple, TypeVar, Optional
    T = TypeVar('T')
    
    # Enter your Python code here
    from __future__ import annotations
    import os
    import sys
    import pya
    import math
    import typing 
    

    Regards
    Tracy

  • Matthias,

    I have solved the Protocol module issue based on the
    following https://pypi.org/project/typing-extensions/

    1) download https://pypi.org/project/typing-extensions/#files
    https://files.pythonhosted.org/packages/16/06/0f7367eafb692f73158e5c5cbca1aec798cdf78be5167f6415dd4205fa32/typing_extensions-3.7.4.3.tar.gz .

    2) Extract the tar file then change to the directory typing_extensions-3.7.4.3
    find either the src_py2 or src_py3 , depending on python version used in Klayout,
    cd to either src dir

    3) then copy typing_extensions, to C:\Users....\AppData\Roaming\KLayout\lib\python3.7

    I have tested and this works this could be added to Salt but I do not know how
    this opens up all kinds of possibilities .

    Again thanks for providing this great tool

    Regards
    Tracy

    Code as follows based on Klayout 0.26.9

                from __future__ import annotations
                import os
                import sys
                import pya
                import math
                import typing 
                # some of these types are deprecated: https://www.python.org/dev/peps/pep-0585/
                from typing import  Dict, List, Iterator, Tuple, TypeVar, Optional
                from typing_extensions import Protocol
                T = TypeVar('T')
    
                 Location = TypeVar('Location')
                         class Graph(Protocol):
                 def neighbors(self, id: Location) -> List[Location]: pass
    
                 class SimpleGraph:
                         def __init__(self):
                         self.edges: Dict[Location, List[Location]] = {}
    
                 def neighbors(self, id: Location) -> List[Location]:
                        return self.edges[id]
    
  • Hi Tracy,

    thanks for sharing this code and the recipe for installing the extension.

    Matthias

  • Matthias
    Anytime to help the user community ,
    We all learn as we go with this great tool.
    Now if I could get EasyGui to work in the same way :)

  • Very good :)

    BTW: in the recent 0.26.10 version, I have included "typing" in the Windows installation.

    Best regards,

    Matthias

Sign In or Register to comment.