Cannot import Draft library

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
xbit
Posts: 140
Joined: Mon Sep 21, 2020 10:48 am

Re: Cannot import Draft library

Post by xbit »

When i typed inside a freecad-daily interactive python console:

Code: Select all

import PySide
import PySide2
both of these worked. No complaint.

But how can i use these outside of an interactive freecad-daily python shell, and use a standalone python script?
All i want to do is load the Draft module.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Cannot import Draft library

Post by Kunda1 »

Cyril wrote: pinged by pinger macro
What's the thread you wrote about being able to do this ? :point_up_2:
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
xbit
Posts: 140
Joined: Mon Sep 21, 2020 10:48 am

Re: Cannot import Draft library

Post by xbit »

Who? Me? I am confused.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Cannot import Draft library

Post by jmaustpc »

xbit wrote: Fri Oct 16, 2020 2:49 pm Who? Me? I am confused.
No, he's asking Cyril, :)
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Cannot import Draft library

Post by sgrogan »

Try this from system Python console

Code: Select all

import sys
sys.path.append("<path to FreeCAD.so>")
import FreeCAD
import Draft
import PySide2
I am not sure what the <path to FreeCAD.so> is.
EDIT: I guess for the daily version it should be usr\lib\freecad-daily-python3\lib
EDIT2: Also I think python defaults to python3 on 20.04, but you may try to start with python3 to check.
EDIT3:

Code: Select all

import sys
sys.path.append("usr\lib\freecad-daily-python3\lib")
import FreeCAD
import Draft
"fight the good fight"
xbit
Posts: 140
Joined: Mon Sep 21, 2020 10:48 am

Re: Cannot import Draft library

Post by xbit »

Same thing.
I have already tried that.
When i import Draft i get:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/share/freecad-daily/Mod/Draft/Draft.py", line 53, in <module>
    from draftutils.utils import ARROW_TYPES as arrowtypes
  File "/usr/share/freecad-daily/Mod/Draft/draftutils/utils.py", line 39, in <module>
    import PySide.QtCore as QtCore
ModuleNotFoundError: No module named 'PySide'
Is it only me who gets this error?
Last edited by xbit on Mon Oct 19, 2020 9:35 am, edited 1 time in total.
xbit
Posts: 140
Joined: Mon Sep 21, 2020 10:48 am

Re: Cannot import Draft library

Post by xbit »

Code: Select all

pip install pyside
does not work, as pyside does not work with python 3.8

Code: Select all

pip install pyside2
worked, however, when i try to

Code: Select all

import Draft
, i still get:

Code: Select all

>>> import Draft
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/share/freecad-daily/Mod/Draft/Draft.py", line 53, in <module>
    from draftutils.utils import ARROW_TYPES as arrowtypes
  File "/usr/share/freecad-daily/Mod/Draft/draftutils/utils.py", line 39, in <module>
    import PySide.QtCore as QtCore
ModuleNotFoundError: No module named 'PySide'
xbit
Posts: 140
Joined: Mon Sep 21, 2020 10:48 am

Re: Cannot import Draft library

Post by xbit »

I used this:

Code: Select all

import sys
for p in sys.path:
	print (p)
and got a list of alla the paths.

Code: Select all

/usr/share/freecad-daily/Mod/Idf
/usr/share/freecad-daily/Mod/PartDesign
/usr/share/freecad-daily/Mod/Tux
/usr/share/freecad-daily/Mod/Show
/usr/share/freecad-daily/Mod/Path
/usr/share/freecad-daily/Mod/Robot
/usr/share/freecad-daily/Mod/TechDraw
/usr/share/freecad-daily/Mod/Sketcher
/usr/share/freecad-daily/Mod/Points
/usr/share/freecad-daily/Mod/Raytracing
/usr/share/freecad-daily/Mod/Measure
/usr/share/freecad-daily/Mod/Inspection
/usr/share/freecad-daily/Mod/MeshPart
/usr/share/freecad-daily/Mod/Surface
/usr/share/freecad-daily/Mod/Import
/usr/share/freecad-daily/Mod/Material
/usr/share/freecad-daily/Mod/Fem
/usr/share/freecad-daily/Mod/Mesh
/usr/share/freecad-daily/Mod/Drawing
/usr/share/freecad-daily/Mod/ReverseEngineering
/usr/share/freecad-daily/Mod/Part
/usr/share/freecad-daily/Mod/Start
/usr/share/freecad-daily/Mod/Image
/usr/share/freecad-daily/Mod/OpenSCAD
/usr/share/freecad-daily/Mod/AddonManager
/usr/share/freecad-daily/Mod/Arch
/usr/share/freecad-daily/Mod/Test
/usr/share/freecad-daily/Mod/Draft
/usr/share/freecad-daily/Mod/Spreadsheet
/usr/share/freecad-daily/Mod/Web
/usr/share/freecad-daily/Mod
/usr/lib/freecad-daily-python3/lib
/usr/share/freecad-daily/Ext
/usr/lib/freecad-daily/bin
/usr/lib/python38.zip
/usr/lib/python3.8
/usr/lib/python3.8/lib-dynload
/usr/local/lib/python3.8/dist-packages
/usr/lib/python3/dist-packages
/home/user1/.FreeCAD/Macro
/usr/lib/freecad-daily/Macro
Then i

Code: Select all

sys.path.append()
all of them, then finally i imported Draft. This is the new error

Code: Select all

>>> import Draft
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/share/freecad-daily/Mod/Draft/Draft.py", line 53, in <module>
  File "/usr/share/freecad-daily/Mod/Draft/draftutils/utils.py", line 39, in <module>
  File "/usr/share/freecad-daily/Ext/PySide/QtCore.py", line 1, in <module>
  File "/home/user1/anaconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 146, in _import
ImportError: /lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.15' not found (required by /home/user1/anaconda3/lib/python3.8/site-packages/PySide2/QtCore.abi3.so)
I had recently performed a

Code: Select all

sudo apt-get install qt
A colleague with the same computer had the same issue when importing Draft. Are we the only ones getting it?
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Cannot import Draft library

Post by jmaustpc »

Are you trying to do this from within FreeCAD in its Python interpretor or are you trying to do this in an external Python interpretor?
xbit
Posts: 140
Joined: Mon Sep 21, 2020 10:48 am

Re: Cannot import Draft library

Post by xbit »

UPDATE:
I managed to import Draft.

When i run

Code: Select all

which python3
, i got

Code: Select all

/home/user1/anaconda3/bin/python3
.
This is the anaconda python. Somehow, i coulnt' load the lirbaries for it.
But FreeCAD uses the default python installation.
So when running

Code: Select all

/usr/bin/python3.8
, everything worked!
Post Reply