Porting to python3

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
maxi3112
Posts: 2
Joined: Thu Aug 23, 2018 7:14 am

Re: Porting to python3

Postby maxi3112 » Thu Aug 23, 2018 10:21 am

Hi everybody,
First of all great work with porting to python3, you're really helping me so much! But i have a newbie question for you:
Grawp wrote:
Sat Aug 18, 2018 2:49 pm
For anyone interested in running FreeCAD with Python 3.7:

https://github.com/Grawp/FreeCAD/tree/python3.7
What can you tell me about the libpack to be used? i downloaded FreeCADLibs_11.8_x64_VC12 with Python2.7 still in it (from https://github.com/sgrogan/FreeCAD/rele ... 18-pre-pre), then in the FreeCAD Cmake i replaced PYTHON_EXECUTABLE, PYTHON_INCLUDE_DIR and PYTHON_LIBRARY with Python3.7 ones but when building with VS2013 it doesn't work; maybe because Boost version coming with that libpack still uses Python2?

Any good input would be helpful :D

P.S. Sorry for my bad english and for my bad building knowledge :lol:
User avatar
sgrogan
Posts: 5469
Joined: Wed Oct 22, 2014 5:02 pm

Re: Porting to python3

Postby sgrogan » Thu Aug 23, 2018 7:32 pm

maxi3112 wrote:
Thu Aug 23, 2018 10:21 am
Any good input would be helpful :D
The Libpacks are all Python2. In addition to boost-python there are other libs that would need to be updated pyside, pivy, and more.

On Win the options are:

Use the pre-build binaries available here: https://github.com/FreeCAD/FreeCAD/rele ... g/0.18_pre

Or to install Miniconda.
On conda-forge FreeCAD PY3.6 packages are available.
Or you can compile yourself using VS2015 or newer using conda as a package manager. See here: https://github.com/FreeCAD/FreeCAD/rele ... g/0.18_pre it's still a work in progress but if you post in that thread we can help with any problems.

I believe @Grawp's work is to extend FreeCAD's PY3 support to include PY3.7, and isn't in master (or conda, still 3.6) yet.

Any use/testing with PY3 is greatly appreciated.
User avatar
yorik
Site Admin
Posts: 11577
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Porting to python3

Postby yorik » Mon Aug 27, 2018 3:32 pm

I just rebuilt FreeCAD with python3 and qt5, using the pivy and pyside packages that @looo's and @kkremitzki have been preparing on debian (pivy self-compiled). Everything fine and running, but I had to make these two little changes:

1) in pivy/CMakeLists.txt:

Code: Select all

5c5
< find_package(Coin CONFIG REQUIRED)
---
> find_package(Coin CONFIG QUIET)
This is because the coin package on debian doesn't provide a .cmake file, so coin cannot be found by standard cmake tools (find_package). The REQUIRED makes cmake fail immediately, without creating cmake stuff in the build dir. By using QUIET instead, it still runs, so one can afterwards go and set Coin_INCLUDE_DIR and Coin_LIB_DIR manually with cmake-gui. Not sure this is the best way to go, though. The cmake step should still fail somehow if coin is not there...

2) the package libpyside2-dev supports several python versions:

Code: Select all

/usr/lib/x86_64-linux-gnu/libpyside2-python2.7.x86_64-linux-gnu.so
/usr/lib/x86_64-linux-gnu/libpyside2.cpython-36m-x86_64-linux-gnu.so
/usr/lib/x86_64-linux-gnu/libpyside2.cpython-37m-x86_64-linux-gnu.so
however it has a cmake file just for one:

Code: Select all

/usr/lib/x86_64-linux-gnu/cmake/PySide2-5.11.0/PySide2Config-python2.7.x86_64-linux-gnu.cmake
So I added a new one manually: PySide2Config.cpython-36m-x86_64-linux-gnu.cmake with this content:

Code: Select all

#  PYSIDE_INCLUDE_DIR   - Directories to include to use PySide2
#  PYSIDE_LIBRARY       - Files to link against to use PySide2
#  PYSIDE_PYTHONPATH    - Path to where the PySide2 Python module files could be found
#  PYSIDE_TYPESYSTEMS   - Type system files that should be used by other bindings extending PySide2

SET(PYSIDE_INCLUDE_DIR "/usr/include/PySide2")
# Platform specific library names
if(MSVC)
    SET(PYSIDE_LIBRARY "/usr/lib/x86_64-linux-gnu/libpyside2.cpython-36m-x86_64-linux-gnu.lib")
elseif(CYGWIN)
    SET(PYSIDE_LIBRARY "/usr/lib/x86_64-linux-gnu/libpyside2.cpython-36m-x86_64-linux-gnu")
elseif(WIN32)
    SET(PYSIDE_LIBRARY "/usr/bin/libpyside2.cpython-36m-x86_64-linux-gnu.so")
else()
    SET(PYSIDE_LIBRARY "/usr/lib/x86_64-linux-gnu/libpyside2.cpython-36m-x86_64-linux-gnu.so")
endif()
SET(PYSIDE_PYTHONPATH "/usr/lib/python3.6m/dist-packages")
SET(PYSIDE_TYPESYSTEMS "/usr/share/PySide2/typesystems")
I suppose another one is needed for py37 too. Is it possible to make a PR somewhere, Kurt? Or can you take care of this?
triplus
Posts: 8796
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Postby triplus » Mon Aug 27, 2018 3:43 pm

This is likely related to this debate:

https://forum.freecadweb.org/viewtopic. ... 90#p250966

P.S. In short in such scenario (and in the future when this gets tackled in Debian packages) you will likely end up being able to set the PYTHON_BASENAME.
User avatar
kkremitzki
Posts: 1795
Joined: Thu Mar 03, 2016 9:52 pm
Location: Texas

Re: Porting to python3

Postby kkremitzki » Mon Aug 27, 2018 11:59 pm

yorik wrote:
Mon Aug 27, 2018 3:32 pm
I suppose another one is needed for py37 too. Is it possible to make a PR somewhere, Kurt? Or can you take care of this?
I filed a bug for this: https://bugs.debian.org/cgi-bin/bugrepo ... bug=906020. The source repo for this package is at https://salsa.debian.org/qt-kde-team/qt/pyside2. It's on my list of things to try to figure out but the list is definitely not short, unfortunately.
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.
looo
Posts: 2954
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Postby looo » Tue Aug 28, 2018 8:29 am

yorik wrote:This is because the coin package on debian doesn't provide a .cmake file, so coin cannot be found by standard cmake tools (find_package). The REQUIRED makes cmake fail immediately, without creating cmake stuff in the build dir. By using QUIET instead, it still runs, so one can afterwards go and set Coin_INCLUDE_DIR and Coin_LIB_DIR manually with cmake-gui. Not sure this is the best way to go, though. The cmake step should still fail somehow if coin is not there...
There is also a setup_old.py which makes it possible to configure pivy without cmake.
please help with my conda-packaging efforts: https://liberapay.com/looooo/
Grawp
Posts: 9
Joined: Sat Mar 03, 2018 9:34 am

Re: Porting to python3

Postby Grawp » Fri Aug 31, 2018 8:39 pm

I've created a PR with a quick fix for python 3.7. Could somebody have a look at it at https://github.com/FreeCAD/FreeCAD/pull/1631 ? I'm also not sure whether it should be linked with https://www.freecadweb.org/tracker/view.php?id=995 or whether it should have dedicated tracker's issue or if tracker's issue is not needed.

Regarding calls to internal Python API.. I've not removed them yet, just made them work with py3.7. Removing them IMHO deserves its own PR/issue and it won't be completely trivial.
User avatar
kkremitzki
Posts: 1795
Joined: Thu Mar 03, 2016 9:52 pm
Location: Texas

Re: Porting to python3

Postby kkremitzki » Fri Aug 31, 2018 9:27 pm

kkremitzki wrote:
Mon Aug 27, 2018 11:59 pm
yorik wrote:
Mon Aug 27, 2018 3:32 pm
I suppose another one is needed for py37 too. Is it possible to make a PR somewhere, Kurt? Or can you take care of this?
I filed a bug for this: https://bugs.debian.org/cgi-bin/bugrepo ... bug=906020. The source repo for this package is at https://salsa.debian.org/qt-kde-team/qt/pyside2. It's on my list of things to try to figure out but the list is definitely not short, unfortunately.
This bug is fixed now, just gotta redo the builds for the PPA.
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.
wmayer
Site Admin
Posts: 14992
Joined: Thu Feb 19, 2009 10:32 am

Re: Porting to python3

Postby wmayer » Sat Sep 01, 2018 11:40 am

Grawp wrote:
Fri Aug 31, 2018 8:39 pm
I've created a PR with a quick fix for python 3.7. Could somebody have a look at it at https://github.com/FreeCAD/FreeCAD/pull/1631 ? I'm also not sure whether it should be linked with https://www.freecadweb.org/tracker/view.php?id=995 or whether it should have dedicated tracker's issue or if tracker's issue is not needed.

Regarding calls to internal Python API.. I've not removed them yet, just made them work with py3.7. Removing them IMHO deserves its own PR/issue and it won't be completely trivial.
It looks like there are several OSS projects that use _PyImport_FixupBuiltin too and now suffer from the same problem with Py3.7. gdb folks had the same issue and I think their fix is the most elegant one.

The trick is to provide an init-function that calls PyModule_Create and use PyImport_AppendInittab.

See:
https://bugzilla.redhat.com/show_bug.cgi?id=1577396
https://sourceware.org/git/gitweb.cgi?p ... e50dfacf48
User avatar
waebbl
Posts: 90
Joined: Thu Aug 16, 2018 3:12 pm

Re: Porting to python3

Postby waebbl » Sat Sep 01, 2018 12:26 pm

yorik wrote:
Mon Aug 27, 2018 3:32 pm
I just rebuilt FreeCAD with python3 and qt5, using the pivy and pyside packages that @looo's and @kkremitzki have been preparing on debian (pivy self-compiled). Everything fine and running, but I had to make these two little changes:

1) in pivy/CMakeLists.txt:

Code: Select all

5c5
< find_package(Coin CONFIG REQUIRED)
---
> find_package(Coin CONFIG QUIET)
This is because the coin package on debian doesn't provide a .cmake file, so coin cannot be found by standard cmake tools (find_package).
On gentoo, I also build freecad against python3(.6) and qt5(.11). What I found, is that the FindCoin3D.cmake file provided by freecad seems to be buggy. It doesn't find the coin library on gentoo too. However, in my ebuild script, I simply delete the freecad FindCoin3D.cmake file, as this file is provided by cmake.

Code: Select all

artus /etc # equery belongs /usr/share/cmake/Modules/FindCoin3D.cmake 
 * Searching for /usr/share/cmake/Modules/FindCoin3D.cmake ... 
dev-util/cmake-3.9.6 (/usr/share/cmake/Modules/FindCoin3D.cmake)
This file works well and does find the coin library. You might want to check, whether the cmake provided by debian also provides the file.