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?
Where does FreeCAD find Python modules/Libraries
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Veteran
- Posts: 2764
- Joined: Mon Feb 27, 2012 5:31 pm
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Where does FreeCAD find Python modules/Libraries
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
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
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
- 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
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.
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.
Re: Where does FreeCAD find Python modules/Libraries
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
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
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: Where does FreeCAD find Python modules/Libraries
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.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.
Re: Where does FreeCAD find Python modules/Libraries
Didn't test it but for development/testing purposes likely you can just add the path, as suggested by others, before the import statement.