Error in VirtMat Jupyter kernel installation
Installation of the VirtMat Jupyter kernel as sugested in /vre-language/virtmat_kernel/README.rst
gives the following error message:
(vre-language) [an9294@uc2n995 virtmat_kernel]$ python -m virtmat_kernel.install
Traceback (most recent call last):
File "/usr/lib64/python3.9/runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib64/python3.9/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/pfs/data5/home/kit/scc/an9294/vre-language/virtmat_kernel/virtmat_kernel/__init__.py", line 6, in <module>
from .kernel import VMKernel
File "/pfs/data5/home/kit/scc/an9294/vre-language/virtmat_kernel/virtmat_kernel/kernel.py", line 10, in <module>
from virtmat.language.interpreter.session_manager import Session
File "/pfs/data5/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/interpreter/__init__.py", line 1, in <module>
from .instant_executor import add_value_properties as add_immediate_value_properties
File "/pfs/data5/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/interpreter/instant_executor.py", line 13, in <module>
from virtmat.language.constraints import get_object_import
File "/pfs/data5/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/constraints/__init__.py", line 1, in <module>
from .typechecks import add_type_properties
File "/pfs/data5/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/constraints/typechecks.py", line 15, in <module>
from virtmat.language.metamodel.function import subst
File "/pfs/data5/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/metamodel/__init__.py", line 1, in <module>
from .properties import add_properties
File "/pfs/data5/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/metamodel/properties.py", line 4, in <module>
from virtmat.language.constraints import add_type_properties
ImportError: cannot import name 'add_type_properties' from partially initialized module 'virtmat.language.constraints' (most likely due to a circular import) (/pfs/data5/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/constraints/__init__.py)
The last line read from file kernel.py is from virtmat.language.interpreter.session_manager import Session
Then the stack prints stuff from the interpreter, constraints, and metamodel modules from the environment directory ~/MyPythonEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/
.
This error seems related to the import order of the modules.
A minimal working example to reproduce the error:
- Load/install the vre-middleware environment (MyInstallationDir/vre-language/README.md)
- In an ipython terminal enter:
In [1]: import os
In [2]: from textx import metamodel_from_file
In [3]: from virtmat.language.interpreter.session_manager import Session
- The printed error message is:
ImportError Traceback (most recent call last)
Cell In[3], line 1
----> 1 from virtmat.language.interpreter.session_manager import Session
[...]
ImportError: cannot import name 'add_type_properties' from partially initialized module 'virtmat.language.constraints' (most likely due to a circular import) (/pfs/data5/home/kit/scc/an9294/python_VirtEnvs/vre-language/lib/python3.9/site-packages/virtmat/language/constraints/__init__.py)
The error can be avoided by importing virtmat.language.metamodel
before Session
- In an ipython terminal enter:
In [1]: import os
In [2]: from textx import metamodel_from_file
In [3]: from virtmat.language import metamodel
In [4]: from virtmat.language.interpreter.session_manager import Session
This simple method can be used to circumvent the VirtMat kernel installation error. To use this workaround:
- Edit the
kernel.py
file inMyInstallationDir/vre-language/virtmat_kernel/virtmat_kernel/
"""This module contains a simple version of an IPython Kernel
for the virtmat language
"""
import os
from ipykernel.kernelbase import Kernel
from ipykernel.kernelapp import IPKernelApp
from virtmat.language import metamodel # -> Add this line as workaround for the 'circular dependence' error
from virtmat.language.utilities.errors import error_handler
from virtmat.language.interpreter.session_manager import Session
[...]
- Change to the
MyInstallationDir/vre-language/virtmat_kernel
directory and run thepython -m virtmat.kernel.install
command - The message for succesful installation is printed
Installing Jupyter kernel spec for Virtmat
INFO:traitlets:Installed kernelspec virtmat in .local/share/jupyter/kernels/virtmat
- The installation of the kernel can be verified using the
jupyter kernelspec list
command. The output should include thevirtmat
kernel, for example:
Available kernels:
fireworks $HOME/.local/share/jupyter/kernels/fireworks
virtmat $HOME/.local/share/jupyter/kernels/virtmat <-THIS LINE!
vre-midwr $HOME/.local/share/jupyter/kernels/vre-midwr
- The
VirtMat
kernel should now be available when starting a Jupyter Notebook/Lab instance.
However this method is NOT a permanent fix and should be addressed.