Support relative rule import in interactive environment
See original GitHub issueI’m using lark in a jupyter notebook, and when I try importing from a different .lark
file like so:
%import .opcode.NAME
I got this error:
~/.pyenv/versions/marlin/lib/python3.6/site-packages/lark/load_grammar.py in load_grammar(self, grammar_text, grammar_name)
718 else: # Relative import
719 if grammar_name == '<string>': # Import relative to script file path if grammar is coded in script
--> 720 base_file = os.path.abspath(sys.modules['__main__'].__file__)
721 else:
722 base_file = grammar_name # Import relative to grammar file path if external grammar file
AttributeError: module '__main__' has no attribute '__file__'
Could we add support to relative import in interactive environment like jupyter notebook or ipython prompt?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
python - Relative imports for the billionth time - Stack Overflow
Thus you cannot do relative imports directly from an interactive session. Relative imports are only for use within module files. Two solutions:
Read more >5. The import system — Python 3.11.1 documentation
Some meta path finders only support top level imports. These importers will always return None when anything other than None is passed as...
Read more >Python import: Advanced Techniques and Tips
The Python import system is as powerful as it is useful. In this in-depth tutorial, you'll learn how to harness this power to...
Read more >Import-Module (Microsoft.PowerShell.Core)
This example imports all available modules in the path specified by the $env:PSModulePath environment variable into the current session. PowerShell. Copy. Get- ...
Read more >Using Python environments in VS Code
Configuring Python Environments in Visual Studio Code. ... Note: Variable substitution is only supported in VS Code settings files, it will not work...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Pushed a fix to
master
.This is awesome. Thanks!