user1584421
user1584421

Reputation: 3843

Python - importing other python programs as libraries

I am using FreeCAD. FreeCAD offers many libraries as .so files. Therefore, to use them, i just have to modify .bashrc, in order to include in the PYTHONPATH, the location of the library files. Then it is all a matter of doing import FreeCAD and this works. This is all vanilla right now.

However, there is another library that i cannot import. When i type import Draft, i get that

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'Draft'

I looked up and there is no Draft.so in the library directory. However, in the program's GUI - python console when i type import Draft it works.

I investigated why this happens. I typed:

import Draft
import inspect
inspect.getfile(Draft)

And i got:

'/usr/share/freecad-daily/Mod/Draft/Draft.py'

This is another directory. There is even another folder in this directory, that contains all the Draft function calls, as separate python files. (For example there is a method called Draft.scale(). Inside the directory there is a file called scale.py)

Is there a way to include all these python files, so i can use import Draft, and just works?

Perhaps is it a matter of setting a new PYTHONPATH?

Upvotes: 0

Views: 176

Answers (1)

mnesarco
mnesarco

Reputation: 2778

Just add '/usr/share/freecad-daily/Mod/Draft' to your PYTHONPATH

In general, each subdir inside Mod is a package root.

Upvotes: 1

Related Questions