FreeCAD 0.18 Python3 bindings

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
donjan
Posts: 33
Joined: Wed Jun 21, 2017 11:40 am

FreeCAD 0.18 Python3 bindings

Post by donjan »

Testing 0.18 from the daily repo on Ubuntu:

Code: Select all

$ export PYTHONPATH=/usr/lib/freecad-daily/lib && python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import FreeCAD
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_FreeCAD)
It works as usual when invoking python2 instead.
The console mode also goes for Python2:

Code: Select all

$ /usr/lib/freecad-daily/bin/FreeCADCmd
[SNIP]
>>> import sys; print(sys.version)
2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0]
Other libs I'd like to import in the same scripts are dropping Python2 support soon (https://python3statement.org/), or already have done so (numpy and FEniCS in my case).
Can the daily be built with Python3 bindings (pretty please)?
Or is there another method to monkey-patch this short of building FreeCAD myself?
User avatar
kkremitzki
Veteran
Posts: 2511
Joined: Thu Mar 03, 2016 9:52 pm
Location: Illinois

Re: FreeCAD 0.18 Python3 bindings

Post by kkremitzki »

It's coming soon. I have an experimental dual-build Python 2 & 3 FreeCAD 0.18 available in my personal PPA at https://launchpad.net/~kkremitzki/+archive/ubuntu/ppa but you may run into issues.
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
donjan
Posts: 33
Joined: Wed Jun 21, 2017 11:40 am

Re: FreeCAD 0.18 Python3 bindings

Post by donjan »

After purging the main repo package and installing from your PPA, I get:

Code: Select all

$ export PYTHONPATH=/usr/lib/freecad/lib && python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import FreeCAD
FreeCAD 0.18, Libs: 0.18R
No modules found in /usr/lib/freecad-python3/Mod
During initialization the error No module named 'freecad' occurred
Now despite the error I can load the .so modules and do some work:

Code: Select all

>>> doc = FreeCAD.newDocument('testDoc')
>>> doc.load('/home/donjan/Desktop/test.fcstd')
<unknown exception traceback><class 'ModuleNotFoundError'>: No module named 'BOPTools'
<unknown exception traceback><class 'ModuleNotFoundError'>: No module named 'CompoundTools'
Importing project files......
>>> print(doc.Objects[0].Label)
Box
But the Python modules have issues:

Code: Select all

>>> import Draft
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'Draft'
The import Draft error can be fixed with:

Code: Select all

sudo ln -s /usr/lib/freecad/Mod /usr/lib/freecad-python3/Mod
The "During initialization the error No module named 'freecad' occurred" error can be disappeared with:

Code: Select all

sudo ln -s /usr/lib/freecad/Ext /usr/lib/freecad-python3/Ext
It works for my purposes right now, but no idea how shaky all of this is :)
Thanks!
And soon == ?
jvs
Posts: 1
Joined: Sat Sep 28, 2019 9:19 pm

Re: FreeCAD 0.18 Python3 bindings

Post by jvs »

I had the same problem. The 2 symlinks fixed it. Thanks!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: FreeCAD 0.18 Python3 bindings

Post by Kunda1 »

So is this a post about accessing FreeCAD workbenches/libraries through ones local system? (not within freecad or using the freecad python interpreter (invoking with the -c flag like: freecad -c)), correct ?
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
Post Reply