ZnTrack icon indicating copy to clipboard operation
ZnTrack copied to clipboard

Add current path when using `from_rev`

Open PythonFZ opened this issue 1 year ago • 1 comments

I found that when using zndraw node.atoms --remote . when using src.Node as the node, I get an ModuleNotFoundError: No module named 'src'. The package might be available via 'pip install src'

https://github.com/zincware/ZnTrack/blob/d602167de977040b45a7d09526b7bd49e65456f7/zntrack/cli/init.py#L84

This was fixable by running export PYTHONPATH="${PYTHONPATH}:<PWD>" before

PythonFZ avatar Jun 19 '24 16:06 PythonFZ

need

import sys
import os

sys.path.insert(0, os.getcwd())

PythonFZ avatar Aug 27 '24 07:08 PythonFZ

or more specifically, when using remote=/... the modules from there should be somehow accessible, for a local path, we can sys insert them, when loading from remote this is more difficult.

Maybe also try to reduce the amount of dependencies that are being loaded to a minimum, e.g. to avoid

Traceback (most recent call last):
  File "/work/jpeters/udd_sulfate/.venv/lib/python3.11/site-packages/zntrack/plugins/base.py", line 132, in base_getter
    self.__dict__[name] = func(self, name)
                          ^^^^^^^^^^^^^^^^
  File "/work/jpeters/udd_sulfate/.venv/lib/python3.11/site-packages/zntrack/fields/deps.py", line 19, in _deps_getter
    content = znjson.loads(
              ^^^^^^^^^^^^^
  File "/work/jpeters/udd_sulfate/.venv/lib/python3.11/site-packages/znjson/main.py", line 22, in loads
    return json.loads(data, cls=cls, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tikhome/jpeters/.local/share/uv/python/cpython-3.11.12-linux-x86_64-gnu/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/tikhome/jpeters/.local/share/uv/python/cpython-3.11.12-linux-x86_64-gnu/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tikhome/jpeters/.local/share/uv/python/cpython-3.11.12-linux-x86_64-gnu/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/work/jpeters/udd_sulfate/.venv/lib/python3.11/site-packages/znjson/main.py", line 105, in _object_hook
    return converter().decode_obj(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/jpeters/udd_sulfate/.venv/lib/python3.11/site-packages/znjson/base.py", line 127, in decode_obj
    return self.decode(obj["value"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/jpeters/udd_sulfate/.venv/lib/python3.11/site-packages/zntrack/converter.py", line 103, in decode
    module = importlib.import_module(s["module"])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tikhome/jpeters/.local/share/uv/python/cpython-3.11.12-linux-x86_64-gnu/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'src'

PythonFZ avatar Jul 03 '25 15:07 PythonFZ