CQ-editor icon indicating copy to clipboard operation
CQ-editor copied to clipboard

CQ Editor cannot find files in module search path

Open lenianiva opened this issue 8 months ago • 4 comments

Consider a project setup like this:

/
|- pyproject.toml
|- poetry.lock
|- mylib
    |- __init__.py
    |- mystery.py
|- example
    |- example.py

where

# mystery.py

def mystery():
    return Cq.Workplane().box(10, 5, 5)

in a poetry shell environment, this succeeds:

(mylib-3.12) [example/] $ python3 -c "import mylib.mystery"

but if example.py contains any reference to import mylib.mystery, loading it up in cq-editor will fail, unless the script starts with this:

# example.py
import os, sys, os.path

root = os.path.dirname(os.getcwd())
print(root)

sys.path.append(root)

import mylib.mystery

The spooky thing is after this part of the script is loaded into cq-editor, commenting it out would not reintroduce the import error. Is there a way for cq-editor to recognize the current venv so it can load libraries referenced by cad scripts?

lenianiva avatar Jun 15 '24 05:06 lenianiva