kalhauge / jpamb

JPAMB: Java Program Analysis Micro Benchmarks
BSD 3-Clause "New" or "Revised" License
0 stars 12 forks source link

ModuleNotFoundError: No module named 'tree_sitter' on Windows #9

Open JacobHMartens opened 2 months ago

JacobHMartens commented 2 months ago

All the required packages have been successfully installed in the venv (including tree-sitter). The error occurs because evaluate.py opens a sub-process which calls the system/global python executable instead of the local python executable in .venv/Scripts.

Example error log

Traceback (most recent call last):
    File "<path-to-project>\jpamb\solutions\syntaxer.py", line 32, in <module>
        import tree_sitter
ModuleNotFoundError: No module named 'tree_sitter'
Tool 'syntaxer' failed with Command '['python', 'solutions/syntaxer.py', 'jpamb.cases.Tricky.collatz:(I)V']' returned non-zero exit status 1.
#### Fails in all other cases as well. ####

Work-around

In this case, I was running syntaxer.py which was using the relative path to src/main/java for the srcfile path, but it works with the absolute path instead:

## Change line 27 in syntaxer.py from:
srcfile = (Path("src/main/java") / i["class_name"].replace(".", "/")).with_suffix(
    ".java"
)
## to
srcfile = ((Path(os.getcwd() + "/src/main/java") / i["class_name"]
           .replace(".", "/"))
           .with_suffix(".java"))

and to make sure that the sub-process in evaluate.py uses the venv python executable, I specified the relative path to that executable:

tools:
  syntaxer:
    technologies:
      - tree-sitter
      - python

    executable:
      - .venv\Scripts\python.exe
      - solutions/syntaxer.py

A better work-around might be to activate the venv in the sub-process (in evaluate.py) before running the "tools" on the test cases.

kalhauge commented 2 months ago

I'll leave this issue open in case someone else experience the same problem.