Lark: [New User] Lark import module error

Created on 4 May 2020  ยท  6Comments  ยท  Source: lark-parser/lark

What is your question?

Im new user of lark, Im tried to install lark and it was successful.

/git/apps/compiler ยป sudo -H pip install lark-parser                                                                                                                          
Collecting lark-parser
  Downloading lark_parser-0.8.5-py2.py3-none-any.whl (72 kB)
     |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 72 kB 1.5 MB/s 
Installing collected packages: lark-parser
Successfully installed lark-parser-0.8.5
WARNING: You are using pip version 20.0.2; however, version 20.1 is available.
You should consider upgrading via the '/usr/local/opt/python/bin/python3.7 -m pip install --upgrade pip' command.
~/git/apps/compiler ยป pip3 install lark-parser                                                                                                                                 
Collecting lark-parser
  Using cached lark_parser-0.8.5-py2.py3-none-any.whl (72 kB)
Installing collected packages: lark-parser
Successfully installed lark-parser-0.8.5

If you're having trouble with your code or grammar

When i try to run a example from https://github.com/lark-parser/lark/blob/master/examples/fruitflies.py im getting the following error.

~/git/apps/compiler ยป python lark.py                                                                                                                                       1 โ†ต 
Traceback (most recent call last):
  File "lark.py", line 6, in <module>
    from lark import Lark
  File "/Users/aravindkumar/git/apps/compiler/lark.py", line 6, in <module>
    from lark import Lark
ImportError: cannot import name 'Lark' from 'lark' (/Users/aravindkumar/git/apps/compiler/lark.py)

I even tried check the package execution status all looks good:

/usr/local/lib/python3.7/site-packages/lark ยป ls -al                                                                                                                          
total 304
drwxr-xr-x   21 root          admin    672 May  5 02:15 .
drwxr-xr-x  681 aravindkumar  admin  21792 May  5 02:15 ..
-rw-r--r--    1 root          admin    379 May  5 02:15 __init__.py
drwxr-xr-x   17 root          admin    544 May  5 02:15 __pycache__
-rw-r--r--    1 root          admin    743 May  5 02:15 common.py
-rw-r--r--    1 root          admin   3906 May  5 02:15 exceptions.py
-rw-r--r--    1 root          admin   2793 May  5 02:15 grammar.py
drwxr-xr-x    3 root          admin     96 May  5 02:15 grammars
-rw-r--r--    1 root          admin   1884 May  5 02:15 indenter.py
-rw-r--r--    1 root          admin  13158 May  5 02:15 lark.py
-rw-r--r--    1 root          admin  13599 May  5 02:15 lexer.py
-rw-r--r--    1 root          admin  31034 May  5 02:15 load_grammar.py
-rw-r--r--    1 root          admin  10450 May  5 02:15 parse_tree_builder.py
-rw-r--r--    1 root          admin   8214 May  5 02:15 parser_frontends.py
drwxr-xr-x   12 root          admin    384 May  5 02:15 parsers
-rw-r--r--    1 root          admin   5655 May  5 02:15 reconstruct.py
-rw-r--r--    1 root          admin   5573 May  5 02:15 reconstruct2.py
drwxr-xr-x    7 root          admin    224 May  5 02:15 tools
-rw-r--r--    1 root          admin   5182 May  5 02:15 tree.py
-rw-r--r--    1 root          admin   7529 May  5 02:15 utils.py
-rw-r--r--    1 root          admin  10987 May  5 02:15 visitors.py

I still cant figure whats wrong with the import. Need help here.

question

All 6 comments

You can't name your file lark.py. Python tries to import it and not the package.

Thanks @MegaIng how silly im here :( , yeah it works now..... will explore lark more.. my issue resolved can be closed.

FWIW, I had a similar error when I mistakenly first did pip install lark. I tried to fix this with pip uninstall lark; pip install lark-parser, but still got the cannot import name 'Lark'. Doing pip uninstall lark-parser; pip install lark-parser fixed it for me.

@tsbertalan Sadly, the name 'lark' is taken on pip, so we have to resort to 'lark-parser'. You just need to be aware to not confuse the two packages.

But at @erezsh, did you ever look into PEP 541?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grihabor picture grihabor  ยท  7Comments

AlbertoEAF picture AlbertoEAF  ยท  3Comments

shewitt-au picture shewitt-au  ยท  3Comments

evandrocoan picture evandrocoan  ยท  6Comments

sirex picture sirex  ยท  3Comments