I’m working on wrapping the FreeCAD python API in custom nodes: https://github.com/infeeeee/DynFreeCAD
FreeCAD can be imported as a Python module in other programs or in a standalone Python console, together with all its modules and components.
I append the FreeCAD
bin folder to
sys.path, and everything is working if I call other submodules inside the same python node. But if I want to
import another submodule in another python node, I get ModuleNotFoundErrors.
The strange thing is, if I import the submodule in a first node, then close the graph, and in another graph I import the same submodule later, it will find it.
I don’t know if it’s understandable what is my problem, so here how I can reproduce this bug:
- First I open this simple graph. I get ModuleNotFoundError:
This is sys path, as you can see all FreeCAD folders added successfully:
- After this I close Dynamo, and open it again, but this time I modify the graph to import in the first python node. Now it finds the
- After this I close the graph, (not dynamo just the graph!) and if I load the original script, where I only load the submodule in the second node, it works!
As I want to create separate nodes for separate FreeCAD commands, I want to
import only on the node, where I need that module. Am I doing something wrong, or I found some bug in Dynamo? How I should import modules from custom path?
I can reproduce this bug in Dynamo 2.8 and 2.9. I can’t use 2.7 because of this bug: CPython3: Warning: cannot convert object to target type
As a workaround I was thinking that I could import everything in the first node, but FreeCAD has around 50 submodules, and even more mods, and it won’t work if someone want to use a non-default mod.