Porting to python3

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!
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

regarding the pyside problem: as it seems you have imstalled both pyside libs side by side, the abstraction layer in Ext/PySide is maybe hidden and the qt4 pyside is imported.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

Hi @looo.

The reason on why i was getting crashes was related to this:

https://forum.freecadweb.org/viewtopic. ... 25#p208325

I have seen you already did some work in this area in the past. I reused your work to further improve things:

https://github.com/FreeCAD/FreeCAD/pull/1209

When using PYTHON_SUFFIX and PYTHON_BASENAME i can build both Py2/Qt5 and Py3/Qt5 without the need to result to symlinks. Both builds work after without crashes.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

phpBB [video]
User avatar
Chris_G
Veteran
Posts: 2596
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Porting to python3

Post by Chris_G »

Hi,
I gave a try at building FC with Python3 on Kubuntu 18.04 beta.
My build process has been quite a mess because I also tried to build coin / pyside2 etc ...
I finally gave up Qt5, and just built with Py3.
It seems I now have a working build.
However, I am getting an error with Vector2D.
The following script :

Code: Select all

import Part
box = Part.makeBox(1,2,3)
face1 = box.Faces[0]
line1 = face1.curveOnSurface(face1.Edges[0])[0]
line2 = face1.curveOnSurface(face1.Edges[1])[0]
line1.intersectCC(line2)

Sends me this error :

Code: Select all

Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: module '__FreeCADBase__' has no attribute 'Vector2d'
Is my FC build messed up ? Or do you get the same error ?
Thanks.

Code: Select all

OS: Ubuntu Bionic Beaver (development branch)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13391 (Git)
Build type: Unknown
Branch: master
Hash: c78a02e7824135e7bce5be4ff81a8b8fefb016bf
Python version: 3.6.4+
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: French/France (fr_FR)
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Porting to python3

Post by sgrogan »

Chris_G wrote: Wed Mar 14, 2018 11:44 am Is my FC build messed up ? Or do you get the same error ?
Same here.

Code: Select all

Python 3.6.4 | packaged by conda-forge | (default, Dec 24 2017, 10:11:43) [MSC v.1900 64 bit (AMD64)] on win32
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> import Part
>>> box = Part.makeBox(1,2,3)
>>> face1 = box.Faces[0]
>>> line1 = face1.curveOnSurface(face1.Edges[0])[0]
>>> line2 = face1.curveOnSurface(face1.Edges[1])[0]
>>> line1.intersectCC(line2)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: module '__FreeCADBase__' has no attribute 'Vector2d'
OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13391 (Git)
Build type: Release
Branch: master
Hash: c78a02e7824135e7bce5be4ff81a8b8fefb016bf
Python version: 3.6.4
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/UnitedStates (en_US)
"fight the good fight"
wmayer
Founder
Posts: 20300
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

This works for me.

Code: Select all

Python 3.4.3 (default, Nov 28 2017, 16:44:58) 
[GCC 4.8.4] on linux
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> from FreeCAD import Base
>>> Base.Vector2d()
Vector2 (0.0, 0.0)
However, my Py3 build is a bit outdated:
OS: Ubuntu 14.04.5 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.12754 (Git)
Build type: Unknown
Branch: master
Hash: 1cfae464b4af12c5483c2495fae360bbf3b4c0cd
Python version: 3.4.3
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.7.0
Locale: German/Germany (de_DE)
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

Code: Select all

from FreeCAD import Base
Base.Vector2d()
works for py2 and py3

Code: Select all

import __FreeCADBase__
__FreeCADBase__.Vector2d()
works only in py2. Maybe the second approach shouldn't be used?
https://github.com/FreeCAD/FreeCAD/blob ... p#L263L265
User avatar
Chris_G
Veteran
Posts: 2596
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Porting to python3

Post by Chris_G »

Thanks for testing.
wmayer wrote: Wed Mar 14, 2018 12:51 pm This works for me.
looo wrote: Wed Mar 14, 2018 1:07 pm

Code: Select all

from FreeCAD import Base
Base.Vector2d()
works for py2 and py3
Indeed, this works for me too.
But I would be curious to know if the piece of script of my first post works for you.
wmayer
Founder
Posts: 20300
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

It fails with:
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: Geom2dAPI_ExtremaCurveCurve:LowerDistance
User avatar
Chris_G
Veteran
Posts: 2596
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Porting to python3

Post by Chris_G »

wmayer wrote: Wed Mar 14, 2018 3:40 pm It fails with:
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: Geom2dAPI_ExtremaCurveCurve:LowerDistance
Thanks.
On my Python2 build, the script works :

Code: Select all

import Part
box = Part.makeBox(1,2,3)
face1 = box.Faces[0]
line1 = face1.curveOnSurface(face1.Edges[0])[0]
line2 = face1.curveOnSurface(face1.Edges[1])[0]
line1.intersectCC(line2)
# on my py2 build -> [Vector2 (3.0, 0.0)]
Post Reply