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!
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

I did some tests and on Ubuntu 16.04 (uses Python 2.7.12 by default) this is the additional step needed to compile @looo branch:
cmake-gui.png
cmake-gui.png (34.81 KiB) Viewed 2817 times

Code: Select all

cmake -DPYTHON_LIBRARY="/usr/lib/x86_64-linux-gnu/libpython3.5m.so" -DPYTHON_INCLUDE_DIR="/usr/include/python3.5m" -DPYTHON_EXECUTABLE="/usr/bin/python3" -DPYTHON_SUFFIX=".cpython-35m-x86_64-linux-gnu" -DPYTHON_BASENAME=".cpython-35m-x86_64-linux-gnu" ..
The only module causing some issues during compile time was Path and i turned it off. After FreeCAD starts normally and uses Python 3.5.2. PySide won't be found but that can easily be resolved by installing:

Code: Select all

sudo apt-get install python3-pyside
P.S. I didn't bother with compiling and installing patched Pivy/Netgen. Therefore issues like Draft/Arch WB aren't working can be observed. As for the rest looking good.
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: Porting to python3

Post by easyw-fc »

looo wrote:regarding the python3 port
Hi, it is a bit OT, but I would like to check if some of my FC Macros will need modifications to be ported to python 3 ... is there a way to check the code?
thanks
Maurice
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

easyw-fc wrote:Hi, it is a bit OT, but I would like to check if some of my FC Macros will need modifications to be ported to python 3 ... is there a way to check the code?
you can try to run 2to3 command on the file or directory to see things that are not compatible.
zaleksf
Posts: 4
Joined: Sun Apr 30, 2017 11:33 pm

Re: Porting to python3

Post by zaleksf »

Hi, Thanks for you hard work. I just successfully built and installed the latest git py3-26 version on Debian testing/Stretch x64.

I also did build and install the new versions of pivy and netgen as well, and I did have to 'deselect' the 'Path' module during configuration (in CMake) as the build crashed on that module.

I'll start working with this version of FreeCAD and see how it behaves.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

And what are the main challenges when it comes to merging the Python 3 porting related work done in master? I remember it was mentioned somewhere but i can't find the discussion ATM.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

thanks for testing @triplus and @zaleksf. You are right the Path-workbench is currently not supported. This is caused by new stuff which introduced python3-incompatibilities.

I already tried to create a pullrequest of the base-dir. But the problem is that this includes changes for python2 too and changes to the base-dir will influence other directories. The main problems are the attr -> attro change and the PyFindMethod which is not available with python3. Also I haven't build the python3-branch with python2 for some time. So merging everything at once is not a good approach.
So the better way is to rearrange the commits, so they do not overlap and can be merged independently.

Another problem are the PyLongChecks which fail for python2 ints. So there it is always necessary to check against python2 ints too. Better we go for define Py::Int as Py::Long in python3. This is actually a feature of PyCXX which just has to be enabled by: https://github.com/FreeCAD/FreeCAD/blob ... x#L800L806 But this will lead to the need to revert many many #ifdef Py_MAJOR_VERSION...

also see here: https://github.com/FreeCAD/FreeCAD/pull/636
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

Thanks for the explanation.

P.S. Is there a chance conda is getting in the way a bit? As if you would use "Linux" directly you could have 2 out of source builds (without installing). One build folder for Python 2 and one for Python 3. Things like applying changes to source code, compiling the changes and doing tests on Python 2 and 3 builds would therefore be easy and fast? And pushing the changes after if tests are OK.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

triplus wrote:P.S. Is there a chance conda is getting in the way a bit? As if you would use "Linux" directly you could have 2 out of source builds (without installing). One build folder for Python 2 and one for Python 3. Things like applying changes to source code, compiling the changes and doing tests on Python 2 and 3 builds would therefore be easy and fast? And pushing the changes after if tests are OK.
No I don't think so. This is not a restriction with conda. You can always have multiple builds with one source. Conda just simplifies the gathering of all the dependencies, and virtual environments allow to have custom builds, without installing to the system.

But I am quite tired of building with python2... ;)
User avatar
CADennis
Posts: 31
Joined: Tue Apr 18, 2017 10:12 am

Re: Porting to python3

Post by CADennis »

triplus wrote: [...]P.S. Is there a chance conda is getting in the way a bit? [...]
+1

"... Well not all libraries which an advanced user needs are included. But you can install them ontop via Pip or anything, but of course that will be a bit out-of-sync, i.e. things will crash at your hobby desktop ...".

Virtual Environments were not invented by CONDA/Continuoum Analytics. They are available to any PIP user. Wheels are being enhaced to offer a free alternative to Continuum Analytics' easy Microsoft binary deployments.

If I wanted commercial software for an ROI-calculated business model, I wouldn't spend $1500 for commercial seat license of Xamarin/ContinuoumAnalytics/etc. ... I'd just get the $5000 Autodesk+Matlab box. The efficiency boost would amortize the price difference within 2 months.

I think, looo, you would get much more support and be better synced, if you stepped down from your ContinuumAnalytics-first thinking, and collimated your development environment towards free open source linux distribution maintainers. I have seen some welcoming offers there in the past weeks. ;)
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

I think, looo, you would get much more support and be better synced, if you stepped down from your ContinuumAnalytics-first thinking, and collimated your development environment towards free open source linux distribution maintainers. I have seen some welcoming offers there in the past weeks. ;)
if you have a better option. I tried to get into debian-packages once. I tried pip and still struggle with it. I looked for other package-manager. I think I've wasted enough time.... If linux provides a package-manager for all distros, I may change my opinion, but I don't see that coming.
Post Reply