Add extra python lib path to FreeCAD system path

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
panyixiao
Posts: 17
Joined: Wed Jun 01, 2016 4:14 pm

Add extra python lib path to FreeCAD system path

Post by panyixiao »

Hi,

Can anyone tell me how to edit python path of FreeCAD python interpreter?

As I run
import sys
sys.path

Both in system's python interpreter and FreeCAD interpreter and I got different results. Since I was trying too use a python library which could not be found by FreeCAD's interpreter (But it works well in system's interpreter), I wonder if there is anyway to edit the path of FreeCAD's python interpreter.

Thanks!
User avatar
yorik
Founder
Posts: 13630
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Add extra python lib path to FreeCAD system path

Post by yorik »

yes, you can add other paths to sys.path, simply like this:

Code: Select all

import sys
sys.path.append("/path/to/my/other/libs")
panyixiao
Posts: 17
Joined: Wed Jun 01, 2016 4:14 pm

Re: Add extra python lib path to FreeCAD system path

Post by panyixiao »

yorik wrote:yes, you can add other paths to sys.path, simply like this:

Code: Select all

import sys
sys.path.append("/path/to/my/other/libs")
Hi, yorik,
I just did, in FreeCAD interpreter, and it seems that the path has been added as well (By printing everything)
It is actually the ros python library, The weird thing is, when I added the path, and try to import the lib in interpreter under FreeCAD Gui , it reports no error, which means FreeCAD is able to locate the lib. But when I running my code (written in C++ but it should be calling that python lib), the console reports an ImportError: No module named catkin.find_in_workspaces. Is there any way that I can add the path to FreeCAD's interpreter at initial states?
User avatar
yorik
Founder
Posts: 13630
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Add extra python lib path to FreeCAD system path

Post by yorik »

Hm I have no idea... Isn't it possible to modify the sys.path from your C++ code too, before doing the import?
Post Reply