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.
panyixiao
Posts: 17
Joined: Wed Jun 01, 2016 4:14 pm

Add extra python lib path to FreeCAD system path

Postby panyixiao » Sun Jun 26, 2016 2:24 pm

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
Site Admin
Posts: 11642
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Add extra python lib path to FreeCAD system path

Postby yorik » Sun Jun 26, 2016 2:47 pm

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

Postby panyixiao » Sun Jun 26, 2016 3:02 pm

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
Site Admin
Posts: 11642
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Add extra python lib path to FreeCAD system path

Postby yorik » Mon Jun 27, 2016 4:21 pm

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