Where does FreeCAD find Python modules/Libraries

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Where does FreeCAD find Python modules/Libraries

Post by keithsloan52 »

I have bit a bug, missing function in lxml so am building it from source.
For testing I now need to get my FreeCAD workbench to pick it up from where I have built it.

Also is there something different on the Mac, something about needing a link from the Resources?
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Where does FreeCAD find Python modules/Libraries

Post by Joel_graff »

This can get tricky, and I'm not an expert on it... so I probably shouldn't post, lol.

Anyway, FreeCAD uses it's own Python environment. Usually, pip-installed or apt-installed libraries get picked up, but not always. I learned that the hard way - really confusing at first why FreeCAD can't see libs that the default Python interpreter can.

What that means is the usual approach of modifying the Python path to pick up libraries in a different location likely won't work. Admittedly, I've not dealt with it much, but here's a forum thread that might help (though it's a bit old):

https://forum.freecadweb.org/viewtopic.php?t=8216
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Where does FreeCAD find Python modules/Libraries

Post by DeepSOIC »

see python's sys.path:
https://docs.python.org/3/library/sys.html#sys.path
FreeCAD redefines the path list to some extent, I guess that's why it won't pick up your build. You can add the path via console, but I don't know how to add it permanently, so that FC will add your one at every launch.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Where does FreeCAD find Python modules/Libraries

Post by Kunda1 »

DeepSOIC wrote: Thu Aug 15, 2019 1:45 pm FreeCAD redefines the path list to some extent, I guess that's why it won't pick up your build. You can add the path via console, but I don't know how to add it permanently, so that FC will add your one at every launch.
this makes sense and if not already, should merit a ticket.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
TheMarkster
Veteran
Posts: 5508
Joined: Thu Apr 05, 2018 1:53 am

Re: Where does FreeCAD find Python modules/Libraries

Post by TheMarkster »

DeepSOIC wrote: Thu Aug 15, 2019 1:45 pm see python's sys.path:
https://docs.python.org/3/library/sys.html#sys.path
FreeCAD redefines the path list to some extent, I guess that's why it won't pick up your build. You can add the path via console, but I don't know how to add it permanently, so that FC will add your one at every launch.
Could try to add the code to a python file, e.g. redefine_path.py, then add that file as a command line argument when FreeCAD is opened. But I don't know if the file arguments get executed before the workbench is loaded.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Where does FreeCAD find Python modules/Libraries

Post by triplus »

Didn't test it but for development/testing purposes likely you can just add the path, as suggested by others, before the import statement.
Post Reply