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
amrit3701
Posts: 343
Joined: Mon Jun 13, 2016 5:37 pm

Re: Porting to python3

Post by amrit3701 »

ebrahim raeyat wrote: Fri Nov 30, 2018 2:05 pm I have problem with Draft.makelabel. in python console or icon in toolbar it gives me this error:

Code: Select all

Traceback (most recent call last):
  File "/home/ebi/miniconda3/envs/fc_test/Mod/Draft/Draft.py", line 7158, in onChanged
    v.multiply(vobj.TextSize/10)
<class 'TypeError'>: unsupported operand type(s) for /: 'Base.Quantity' and 'int'
FreeCAD 0.18 python3 conda build. Thanks
Use vobj.TextSize.Value instead of vobj.TextSize

For eg.

Code: Select all

v.multiply(vobj.TextSize.Value/10)
Amritpal Singh
Github, Like my work, sponsor me!
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Porting to python3

Post by ebrahim raeyat »

amrit3701 wrote: Sun Dec 02, 2018 4:47 pm

Use vobj.TextSize.Value instead of vobj.TextSize

For eg.

Code: Select all

v.multiply(vobj.TextSize.Value/10)
Thanks. do you also have this problem? this is in core of FreeCAD, not in my code.
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Porting to python3

Post by ebrahim raeyat »

looo wrote: Fri Nov 30, 2018 3:50 pm
I guess this one should be fixed in a more recent build. Can you try again with an updated FreeCAD and post your full version info.
Thanks. I ran latest version and it works correctly.

OS: Manjaro Linux
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15303 (Git)
Build type: Release
Branch: master
Hash: 6199c95fd71eacb9cc168426e55254aa79a42034
Python version: 3.6.7
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: Porting to python3

Post by easyw-fc »

as in this thread
the Conda build has a FEM Elmer solver issue:

Code: Select all

Traceback (most recent call last):
  File "C:\FreeCAD\Mod\Fem\femsolver\solverbase.py", line 79, in setEdit
    machine = run.getMachine(vobj.Object)
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 54, in getMachine
    _DocObserver.attach()
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 334, in attach
    cls._instance = cls()
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 326, in __init__
    for doc in App.listDocuments().itervalues():
<class 'AttributeError'>: 'dict' object has no attribute 'itervalues'
Traceback (most recent call last):
  File "C:\FreeCAD\Mod\Fem\femsolver\solverbase.py", line 79, in setEdit
    machine = run.getMachine(vobj.Object)
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 54, in getMachine
    _DocObserver.attach()
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 334, in attach
    cls._instance = cls()
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 326, in __init__
    for doc in App.listDocuments().itervalues():
<class 'AttributeError'>: 'dict' object has no attribute 'itervalues'
Traceback (most recent call last):
  File "C:\FreeCAD\Mod\Fem\femsolver\solverbase.py", line 79, in setEdit
    machine = run.getMachine(vobj.Object)
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 54, in getMachine
    _DocObserver.attach()
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 334, in attach
    cls._instance = cls()
  File "C:\FreeCAD\Mod\Fem\femsolver\run.py", line 326, in __init__
    for doc in App.listDocuments().itervalues():
<class 'AttributeError'>: 'dict' object has no attribute 'itervalues'
bernd wrote: ping
and the FC details:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15340 (Git)
Build type: Release
Branch: master
Hash: 14b780c0ee9a0cd4adc2dc7abdff94ed315dd781
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

Similar to git commit 1dbbb4371
the dict.itervalues() should be replaced with iter(dict.values())
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: Porting to python3

Post by easyw-fc »

wmayer wrote: Fri Dec 07, 2018 6:19 pm Similar to git commit 1dbbb4371
the dict.itervalues() should be replaced with iter(dict.values())
I made a PR https://github.com/FreeCAD/FreeCAD/pull/1822
There are then other issues:

Code: Select all

Exception in thread Thread-12:
Traceback (most recent call last):
  File "C:\FreeCAD_Py3QT5\bin\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\FreeCAD_Py3QT5\bin\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\FreeCAD_Py3QT5\Mod\Fem\femsolver\task.py", line 115, in protector
    self.run()
  File "C:\FreeCAD_Py3QT5\Mod\Fem\femsolver\elmer\tasks.py", line 103, in run
    output = self._observeSolver(self._process)
  File "C:\FreeCAD_Py3QT5\Mod\Fem\femsolver\elmer\tasks.py", line 116, in _observeSolver
    output += line
TypeError: must be str, not bytes
EDIT:
the PR should be fine now
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Porting to python3

Post by ebrahim raeyat »

Thank you so much @yorik.

I wanted to compile FreeCAD 0.18 on manjaro linux. manjaro is based on Arch Linux and i follow the instruction in this page:

https://www.freecadweb.org/wiki/CompileOnUnix

I installed all dependency (i have doubt about correct version as i want to compile for python3), but i ran this command:

Code: Select all

cmake-gui
and configure files. the output is ok:

Code: Select all

Compiler: GNU, version: 8.2.1
prefix: /usr/local
datadir: data
docdir: doc
includedir: include
libdir: /usr/local/lib
cmake: 3.12.4
Boost version: 1.68.0
Found the following Boost libraries:
  filesystem
  program_options
  regex
  system
  thread
  chrono
  date_time
  atomic
Found Xerces-C: /usr/lib/libxerces-c.so
PyCXX found:
  Headers:  /run/media/ebi/home/ebi/FreeCAD/freecad-code/src
  Sources:  /run/media/ebi/home/ebi/FreeCAD/freecad-code/src/CXX
  Version:  6.2.8
-- Found OCE/OpenCASCADE version: 7.3.0
-- OCE/OpenCASCADE include directory: /usr/include/opencascade
-- OCE/OpenCASCADE shared libraries directory: /usr/lib
Successfully loaded VTK-m component Base
VTK components: vtkCommonCore;vtkCommonDataModel;vtkFiltersVerdict;vtkIOXML;vtkFiltersCore;vtkFiltersGeneral;vtkIOLegacy;vtkFiltersExtraction;vtkFiltersSources;vtkFiltersGeometry;vtkIOMPIParallel;vtkParallelMPI;vtkhdf5;vtkFiltersParallelDIY2;vtkRenderingCore;vtkInteractionStyle;vtkRenderingFreeType;vtkRenderingOpenGL2
Successfully loaded VTK-m component Base
Checking for one of the modules 'hdf5-serial'
HDF5: Using hdf5 compiler wrapper to determine C configuration
Check for medfile (libmed and libmedc) ...
Checking for module 'Coin'
  Found Coin, version 3.1.3
Using default python: .cpython-37m-x86_64-linux-gnu
libshiboken built for Release
Found PySide Tools: /usr/bin/python2-pyside-uic, /usr/bin/pyside-rcc
-- matplotlib-2.2.3 has been found.
Platform is 64-bit, set -D_OCC64
Build type: 
git
/run/media/ebi/home/ebi/FreeCAD/freecad-build/src/Build/Version.h.out written

Note: Doxygen docs will look better with graphviz's dot installed.
Coin3D doc is installed
  Tag file: /usr/share/doc/coin/html/coin.tag
  Location: /usr/share/doc/coin/html
=======================================
[color=#FF0000]Now run 'make' to build FreeCAD[/color]
=======================================

Configuring done
then I make and it gives me this error at the end:

Code: Select all

[ 78%] Linking CXX shared library ../../../../Mod/Part/PartGui.so
[ 78%] Built target PartGui
make: *** [Makefile:130: all] Error 2
although it builds in bin directory FreeCAD and FreeCADCmd. I run FreeCAD to view what happen. it gives me this error:

Code: Select all

Error in InitApplications type '_io._IOBase' participates in gc and is a base type but has inappropriate tp_free slot
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "<string>", line 241, in <module>
  File "<string>", line 54, in InitApplications
  File "/usr/lib/python2.7/io.py", line 51, in <module>
    import _io
TypeError: type '_io._IOBase' participates in gc and is a base type but has inappropriate tp_free slot
--------------------------------------------------------------------------------
Program received signal SIGSEGV, Segmentation fault.
#0  /usr/lib/libc.so.6(+0x37e00) [0x7f5654f3ae00]
#1  /usr/lib/libpython2.7.so.1.0(PyObject_GetAttrString+0xd) [0x7f565a265c8d]
#2  /usr/lib/libpython2.7.so.1.0(PyObject_HasAttrString+0xa) [0x7f565a265d6a]
#3  /usr/lib/libpython2.7.so.1.0(PyImport_ImportModuleLevel+0x242) [0x7f565a2c59f2]
my questions:

1- it gives me the python2.7 in error. is it compiled for python 2.7 not python 3.7. I set the PYTHON_BASENAME and PYTHON_CONFIG_SUFFIX to .cpython-37m-x86_64-linux-gnu. Is that manual page out date? Is there an update page for installation?

2- I can't understand is FreeCAD ver 0.18 work with pyside2 or pyqt5 or both of them and what those is default? is there a page that tell about this?

3- what is the easiest way to have up to date FreeCAD with python3. I mean last changed on github? I examin AppImage but it gives me Segmentation fault

Thanks a lot.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

ebrahim raeyat wrote: Mon Dec 10, 2018 6:42 am 1- it gives me the python2.7 in error. is it compiled for python 2.7 not python 3.7. I set the PYTHON_BASENAME and PYTHON_CONFIG_SUFFIX to .cpython-37m-x86_64-linux-gnu. Is that manual page out date? Is there an update page for installation?
Didn't test it yet, but some changes were introduced recently:

https://forum.freecadweb.org/viewtopic. ... ad#p271373
I examin AppImage but it gives me Segmentation fault
If you start it from the terminal. Does it produce any more clues there?
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

ebrahim raeyat wrote: Mon Dec 10, 2018 6:42 am 1- it gives me the python2.7 in error. is it compiled for python 2.7 not python 3.7. I set the PYTHON_BASENAME and PYTHON_CONFIG_SUFFIX to .cpython-37m-x86_64-linux-gnu. Is that manual page out date? Is there an update page for installation?
Yes in systems with multiple version of dependencies it is known that FreeCAD is difficult to be build. Systems and FreeCAD are currently supporting all combinations of qt4 / qt5 py2/py3. Setting up an automatic procedure which always selects the wanted combination is very difficult because there are also differences in distros...

Conda solves this situation by using environments. Every environment shouldn't have multiple versions of the same dependency. So there is only one python and only one qt. So this way the dependency-handling is a bit simpler.
In my eyes a system should also focus on the one version per library approach. Many difficulties and bugs are introduced by allowing to install multiple versions. I hope there will be a python3-only qt5-only distro be available n the near future. Ever other combination of dependency version can be achieved by using appimages, conda, flatpack, and so on.
ebrahim raeyat wrote: Mon Dec 10, 2018 6:42 am 2- I can't understand is FreeCAD ver 0.18 work with pyside2 or pyqt5 or both of them and what those is default? is there a page that tell about this?
FreeCAD needs either qt4-pyside or qt5-pyside2. PyQt4/5 currently doesn't work for FreeCAD (some work would be needed to get this done. But I don't think this will have much advantage.)
ebrahim raeyat wrote: Mon Dec 10, 2018 6:42 am 3- what is the easiest way to have up to date FreeCAD with python3. I mean last changed on github? I examin AppImage but it gives me Segmentation fault
Latest available version doesn't gives segfault for me: OS: Ubuntu 18.04.1 LTS Version: 0.18.15363 (Git) AppImage
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Porting to python3

Post by ebrahim raeyat »

triplus wrote: Mon Dec 10, 2018 10:50 am If you start it from the terminal. Does it produce any more clues there?
Thanks. yes, it is:

Code: Select all

[ebi@ebrahim-pc bin]$ ./FreeCAD
FreeCAD 0.18, Libs: 0.18R15316 (Git)
© Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2018
  #####                 ####  ###   ####  
  #                    #      # #   #   # 
  #     ##  #### ####  #     #   #  #   # 
  ####  # # #  # #  #  #     #####  #   # 
  #     #   #### ####  #    #     # #   # 
  #     #   #    #     #    #     # #   #  ##  ##  ##
  #     #   #### ####   ### #     # ####   ##  ##  ##

Error in InitApplications type '_io._IOBase' participates in gc and is a base type but has inappropriate tp_free slot
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "<string>", line 241, in <module>
  File "<string>", line 54, in InitApplications
  File "/usr/lib/python2.7/io.py", line 51, in <module>
    import _io
TypeError: type '_io._IOBase' participates in gc and is a base type but has inappropriate tp_free slot
--------------------------------------------------------------------------------
Program received signal SIGSEGV, Segmentation fault.
#0  /usr/lib/libc.so.6(+0x37e00) [0x7fa57394be00]
#1  /usr/lib/libpython2.7.so.1.0(PyObject_GetAttrString+0xd) [0x7fa578c76c8d]
#2  /usr/lib/libpython2.7.so.1.0(PyObject_HasAttrString+0xa) [0x7fa578c76d6a]
#3  /usr/lib/libpython2.7.so.1.0(PyImport_ImportModuleLevel+0x242) [0x7fa578cd69f2]
#4  /usr/lib/libpython2.7.so.1.0(+0x12822a) [0x7fa578cdd22a]
#5  /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x43) [0x7fa578c3f0e3]
#6  /usr/lib/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x31) [0x7fa578cf57d1]
#7  /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x3a28) [0x7fa578c9e8a8]
#8  /usr/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca) [0x7fa578cf60da]
#9  /usr/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x1a) [0x7fa578d1530a]
#10  /usr/lib/libpython2.7.so.1.0(PyImport_ExecCodeModuleEx+0xc1) [0x7fa578d2bfb1]
#11  /usr/lib/libpython2.7.so.1.0(+0x17719a) [0x7fa578d2c19a]
#12  /usr/lib/libpython2.7.so.1.0(+0x12104e) [0x7fa578cd604e]
#13  /usr/lib/libpython2.7.so.1.0(PyImport_ImportModuleLevel+0x1d1) [0x7fa578cd6981]
#14  /usr/lib/libpython2.7.so.1.0(+0x12822a) [0x7fa578cdd22a]
#15  /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x43) [0x7fa578c3f0e3]
#16  /usr/lib/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x31) [0x7fa578cf57d1]
#17  /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x3a28) [0x7fa578c9e8a8]
#18  /usr/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca) [0x7fa578cf60da]
#19  /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5f3f) [0x7fa578ca0dbf]
#20  /usr/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca) [0x7fa578cf60da]
#21  /usr/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x1a) [0x7fa578d1530a]
#22  /usr/lib/libpython2.7.so.1.0(+0x16ba81) [0x7fa578d20a81]
#23  /usr/lib/libpython2.7.so.1.0(PyRun_StringFlags+0x66) [0x7fa578d225d6]
#24  0x7fa5791c98b7 in Base::InterpreterSingleton::runString[abi:cxx11](char const*) from /run/media/ebi/home/ebi/FreeCAD/freecad-build/lib/libFreeCADBase.so+0xe7
#25  0x7fa57a7d3306 in Gui::Application::runInitGuiScript() from /run/media/ebi/home/ebi/FreeCAD/freecad-build/lib/libFreeCADGui.so+0x46
#26  0x7fa57a7d4e59 in Gui::Application::runApplication() from /run/media/ebi/home/ebi/FreeCAD/freecad-build/lib/libFreeCADGui.so+0x1b2b
#27  ./FreeCAD(main+0xa89) [0x55db29db80d2]
#28  /usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7fa573938223]
#29  ./FreeCAD(_start+0x2e) [0x55db29db74be]
Post Reply