PySide for Mod/Draft in NoGUI build

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
manuel-buchner
Posts: 5
Joined: Wed Jun 02, 2021 8:52 am

PySide for Mod/Draft in NoGUI build

Post by manuel-buchner »

Hi everyone,

i like to Import IFC Files using Mod/Arch/importIFC.py

I am building FreeCAD in a Alpine Docker container, without a GUI (version 0.19.2)

Code: Select all

cmake ../FreeCAD \
    -DCMAKE_BUILD_TYPE=Release \
    -DPYTHON_EXECUTABLE=/usr/bin/python3 \
    -DFREECAD_USE_EXTERNAL_SMESH=ON \
    -DBUILD_QT5=ON \
    -DBUILD_PART=ON \
    -DBUILD_MESH=ON \
    -DBUILD_ARCH=ON \
    -DBUILD_FEM=OFF \
    -DBUILD_GUI=OFF \
    -DBUILD_MESH_PART=OFF \
    -DBUILD_COMPLETE=OFF \
    -DBUILD_IMAGE=OFF \
    -DBUILD_INSPECTION=OFF \
    -DBUILD_MATERIAL=OFF \
    -DBUILD_OPENSCAD=OFF \
    -DBUILD_PART_DESIGN=OFF \
    -DBUILD_PATH=OFF \
    -DBUILD_POINTS=OFF \
    -DBUILD_RAYTRACING=OFF \
    -DBUILD_REVERSEENGINEERING=OFF \
    -DBUILD_ROBOT=OFF \
    -DBUILD_SHOW=OFF \
    -DBUILD_START=OFF \
    -DBUILD_SURFACE=OFF \
    -DBUILD_TECHDRAW=OFF \
    -DBUILD_TUX=OFF \
    -DBUILD_WEB=OFF
Therefor I also don't need PySide, but when trying to import a IFC File, I got this error.

Code: Select all

Traceback (most recent call last):
  ...
    import importIFC
  File "/usr/local/Mod/Arch/importIFC.py", line 40, in <module>
    import Draft
  File "/usr/local/Mod/Draft/Draft.py", line 53, in <module>
    from draftutils.utils import ARROW_TYPES as arrowtypes
  File "/usr/local/Mod/Draft/draftutils/utils.py", line 39, in <module>
    import PySide.QtCore as QtCore
ModuleNotFoundError: No module named 'PySide'
It seems like Draft uses PySide, which isn't installed in this container.
Also, on Alpine, I can install py3-pyside2, but "PySide2" cannot be found importing "PySide" (which Mod/Draft/draftutils/utils.py wants to import).

Any ideas, how to import IFC Files in my container?
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: PySide for Mod/Draft in NoGUI build

Post by Kunda1 »

Good effort here. This is a great way to enhance the FreeCAD source code to function better in NoGUI mode.

I'm cofused, isn't pyside relevant here as it is
...the official Python module from the Qt for Python project, which provides access to the complete Qt 5.12+ framework.
Also there may be functionality that is necessary in the src/Mod/OpenSCAD code and perhaps others as well.

Edit: We don't see much alpine linux users here, can you start a python console instance and run

Code: Select all

import PySide2
and see if returns successfully?

Edit2: (ref: https://forum.freecadweb.org/viewtopic. ... 34#p439348)

Code: Select all

$ python3
Python 3.9.5 (default, May  9 2021, 14:00:28) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PySide2
>>> print(PySide2.__file__)
/usr/lib/python3.9/site-packages/PySide2/__init__.py
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
manuel-buchner
Posts: 5
Joined: Wed Jun 02, 2021 8:52 am

Re: PySide for Mod/Draft in NoGUI build

Post by manuel-buchner »

When I install PySide2 from alpine repo (apk add py3-pyside2), I am able to import it. But this won't fix FreeCAD while importing "PySide"

Code: Select all

    ...
    import importIFC
  File "/usr/local/Mod/Arch/importIFC.py", line 40, in <module>
    import Draft
  File "/usr/local/Mod/Draft/Draft.py", line 53, in <module>
    from draftutils.utils import ARROW_TYPES as arrowtypes
  File "/usr/local/Mod/Draft/draftutils/utils.py", line 39, in <module>
    import PySide.QtCore as QtCore
ModuleNotFoundError: No module named 'PySide'
/opt/freecad-build # python3
Python 3.9.5 (default, May 12 2021, 20:44:22)
[GCC 10.3.1 20210424] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PySide
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PySide'
>>> import PySide2
>>>
Edit: When PySide is required in these modules, why isn't it checked in the CMakeLists?
If i am right, PySide is only checked if BUILD_GUI is active (/CMakeLists.txt L75 @ branch 0.19.2)
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: PySide for Mod/Draft in NoGUI build

Post by Kunda1 »

manuel-buchner wrote: Mon Jun 07, 2021 8:10 am Edit: When PySide is required in these modules, why isn't it checked in the CMakeLists?
If i am right, PySide is only checked if BUILD_GUI is active (/CMakeLists.txt L75 @ branch 0.19.2)
Indeed, it looks you're right (link)

Code: Select all

    if(BUILD_GUI)
        SetupCoin3D()
        SetupSpaceball()
        SetupShibokenAndPyside()
        SetupMatplotlib()
    endif(BUILD_GUI)
endif(NOT FREECAD_LIBPACK_USE OR FREECAD_LIBPACK_CHECKFILE_CLBUNDLER)
Edit: Here's the link to SetupShibokenAndPyside.cmake (link)

Edit2: for continuing to tinker with this, I recommend you start using the FreeCAD dev version from https://github.com/FreeCAD/FreeCAD-Bund ... kly-builds

Edit3: We should take a look at how FreeCAD loads dependencies when we start it from the CLI: Headless FreeCAD
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
manuel-buchner
Posts: 5
Joined: Wed Jun 02, 2021 8:52 am

Re: PySide for Mod/Draft in NoGUI build

Post by manuel-buchner »

I already gave up building FreeCAD on alpine by myself, I have no time anymore to investigate more in this topic, but hopefully I gave some input on improving FreeCAD.
doxley
Posts: 35
Joined: Tue Jun 18, 2019 6:55 pm

Re: PySide for Mod/Draft in NoGUI build

Post by doxley »

I'm trying to use Draft in a Headless run (FreeCAD 19/Ubuntu) which I set up with AppImage. In chasing my problems, I found on github (https://github.com/FreeCAD/FreeCAD/blob ... s/utils.py) a note on line 46:

# TODO: move the functions that require the graphical interface
# This module should not import any graphical commands; those should be
# in gui_utils


I searched pretty thoroughly all the related Pull requests and issues and see no evidence of this being dealt with though I have seen other comments along this line such as this thread. Anyone know anything about whether this is being done any time soon? I'd be happy to help, but I think this is well above my pay grade.

Thx,
--Don
Post Reply