FreeCAD / homebrew-freecad

Homebrew recipes for FreeCAD
54 stars 34 forks source link

freecad mac app bundle ie. `FreeCAD.app` runtime issue, cannot find the runtime dependency pyside2 #278

Open ipatch opened 2 years ago

ipatch commented 2 years ago

presently running brew install freecad should either install freecad from one of the provided bottles for catalina or big sur. if running a different OS ie. mojave or monterey then freecad will have to be build from source locally.

so depending how the dependencies are setup ie. pyside2@5.15.2 freecad will fail to load the pyside2 runtime dep when launching the FreeCAD gui when double clicking the app bundle. ie. FreeCAD.app.

presently, either pyside@2 or the tap provided pyside2@5.15.2 need to be manually linked before running

brew install freecad -s -v

and the runtime issue should be resolved, but haven't fully tested.

the CI, cmake scripts or freecad.rb formula file need to be updated to support (finding) the install of pyside in order to copy the necessary dependencies into the FreeCAD.app bundle.

as mentioned in a prior comment ie.

https://github.com/FreeCAD/homebrew-freecad/issues/237#issuecomment-965855376

it may be possible to tweak the freecad gui launch script to specify the path to the pyside2 installation. once again, i haven't fully tested this locally on my machine or with the CI/CD (github actions yet)

ipatch commented 2 years ago

error messages after launching the FreeCAD.app GUI

18:31:43  During initialization the error "No module named 'PySide2'" occurred in /Users/brewmaster/homebrew/Cellar/freecad/0.19/FreeCAD.app/Contents/Mod/Draft/InitGui.py
18:31:43  Please look into the log file for further information
18:31:45  During initialization the error "No module named 'PySide2'" occurred in /Users/brewmaster/homebrew/Cellar/freecad/0.19/FreeCAD.app/Contents/Mod/Arch/InitGui.py
18:31:45  Please look into the log file for further information
18:31:45  During initialization the error "No module named 'PySide2'" occurred in /Users/brewmaster/homebrew/Cellar/freecad/0.19/FreeCAD.app/Contents/Mod/AddonManager/InitGui.py
18:31:45  Please look into the log file for further information
18:31:46  During initialization the error "No module named 'PySide2'" occurred in /Users/brewmaster/homebrew/Cellar/freecad/0.19/FreeCAD.app/Contents/Mod/Tux/InitGui.py
18:31:46  Please look into the log file for further information
18:31:48  Unknown command 'Std_AddonMgr'
18:31:48  Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/Users/brewmaster/homebrew/Cellar/freecad/0.19/FreeCAD.app/Contents/Mod/Start/StartPage/StartPage.py", line 29, in <module>
    from . import TranslationTexts
  File "/Users/brewmaster/homebrew/Cellar/freecad/0.19/FreeCAD.app/Contents/Mod/Start/StartPage/TranslationTexts.py", line 24, in <module>
    from PySide import QtGui
  File "/Users/brewmaster/homebrew/Cellar/freecad/0.19/FreeCAD.app/Contents/MacOS/PySide/__init__.py", line 2, in <module>
    from PySide2 import __version__
<class 'ModuleNotFoundError'>: No module named 'PySide2'
18:31:48  No module named 'PySide2'
ipatch commented 2 years ago

https://github.com/FreeCAD/homebrew-freecad/issues/164#issuecomment-984944471

ipatch commented 2 years ago

image

neurodigitaltechnologies commented 2 years ago

Hi @ipatch, Any updates so far on this issue, please? Many thanks in advance for all your support and hard work on this. All the best, Luis.

ipatch commented 2 years ago

i haven't done any work with the freecad tap or specifically this issue in a week or so. the holidays caught up with me so my time has been limited.

if you're trying to install freecad using the tap provided formula ie. freecad.rb then a possible work around would be the below

install all the freecad dependencies first

brew install freecad/freecad/freecad -v --only-dependenices

manually link pyside2@5.15.2 and shiboken2@5.15.2

brew link -v pyside2@5.15.2
brew link -v shiboken2@5.15.2

then build freecad from source using the tap provided formula

brew install freecad -v -s
vejmarie commented 2 years ago

I am currently looking at it. My build is broken on Mac, and still try to figuring out from where it comes.

vejmarie commented 2 years ago

This PR #5316 in FreeCAD shall be helping a lot

ipatch commented 2 years ago

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

ipatch commented 2 years ago
clyang commented 2 years ago

i haven't done any work with the freecad tap or specifically this issue in a week or so. the holidays caught up with me so my time has been limited.

if you're trying to install freecad using the tap provided formula ie. freecad.rb then a possible work around would be the below

install all the freecad dependencies first

brew install freecad/freecad/freecad -v --only-dependenices

manually link pyside2@5.15.2 and shiboken2@5.15.2

brew link -v pyside2@5.15.2
brew link -v shiboken2@5.15.2

then build freecad from source using the tap provided formula

brew install freecad -v -s

I'm able to build app bundle by using this workaround. However, when I tried to run it, it shows the following error.

During initialization the error "Failed to wrap widget" occurred in /Applications/FreeCAD.app/Contents/Mod/Tux/InitGui.py
Please look into the log file for further information

Is there any solution to this issue?

ipatch commented 2 years ago

@clyang

do you mind opening a new issue, just copy and paste what you go here?

and can you post your brew setup, ie. the output of your brew config , brew doctor

are you using m1 or intel, the more information you can provide the more we're able to help. 🤝

clyang commented 2 years ago

Thanks for the prompt response!

I compiled it on my M1 laptop. After the successful build, here is my steps:

1. cd /opt/homebrew/Cellar/freecad/0.19
2. open FreeCAD.app

My brew doctor

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  tbb@2020
  vtk@8.2

brew config

HOMEBREW_VERSION: 3.4.7
ORIGIN: https://github.com/Homebrew/brew
HEAD: 09e766f83c8a420cce9e2210c46a24ec3864a094
Last commit: 30 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 9e6c2e2b31ec47136266ada0c32a2ecf0589c20e
Core tap last commit: 63 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_CORE_GIT_REMOTE: https://github.com/Homebrew/homebrew-core
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.8 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 13.1.6 build 1316
Git: 2.32.0 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.79.1 => /usr/bin/curl
macOS: 12.3.1-arm64
CLT: 13.3.1.0.1.1648687083
Xcode: 13.3.1
Rosetta 2: false
ipatch commented 2 years ago

little update on this issue. i think the simple solution to getting the cmake build process to properly locate the pyside2 installation is to prepend the pyside installation bin to the path while running cmake. i tested a couple of cases where i had the pyside bin directory prepended (top entry) in my $USER path and without. i get the following snippet without the pyside2 bin path entry...

-- Shiboken2:            [Shiboken2_DIR-NOTFOUND] []
-- PySide2:              []
--  IncludeDir:         Unable to find, python version mismatch?
-- PySide2Tools:        [/usr/local/opt/qt@5/bin/uic] [/usr/local/opt/qt@5/bin/rcc]

when i add pyside2 to my path with the following,

fish_add_path -p $bp/Cellar/pyside@2/5.15.5/bin

and...

brew unlink shiboken2@5.15.5
Unlinking /usr/local/Cellar/shiboken2@5.15.5/5.15.5... 0 symlinks removed.

brew unlink pyside@2
Unlinking /usr/local/Cellar/pyside@2/5.15.5... 0 symlinks removed.

i see the below in the cmake report output...

-- Shiboken2:           5.15.5 [/usr/local/Cellar/pyside@2/5.15.5/lib/cmake/Shiboken2-5.15.5] [/usr/local/Cellar/pyside@2/5.15.5/include/shiboken2;/usr/local/opt/python@3.10/Frameworks/Python.framework/Headers]
-- PySide2:             5.15.5 [/usr/local/Cellar/pyside@2/5.15.5/include/PySide2]
-- PySide2Tools:        [/usr/local/opt/qt@5/bin/uic] [/usr/local/opt/qt@5/bin/rcc]

not sure if this will resolve all the runtime related issues with pyside but seems like a step in the right direction.

ipatch commented 2 years ago

and i think this will help us with keg only deps in the freecad formula ie. pyside2 being keg only because of it's upstream pyside6 counterpart, so if this works then hopefully brew install freecad will just work without having to manually link the keg only deps of shiboken2 and pyside2 🤞

ipatch commented 2 years ago

335

should help in getting closer to having brew install freecad to just work without any manual unlink/link commands

ipatch commented 2 years ago

another little update on this. a quick way to see if shiboken and pyside are setup properly for a cmake build is to open a pythone repl

python3

# i'm using python3 provided by homebrew-core python@3.10
import shiboken2
import PySide2
from PySide2 import QtCore

i was running into some edge cases yesterday where i was able to import PySide2 but was not able to load any of the accompanying qt modules.

i made certain that my shiboken2 and pyside2 installation are not linked.

i got a build going right now (non mac bundle) that seems to have picked up on my shiboken and pyside installations on a m1 mac. however i did have to add a .pth file for each package into my site-packages dir for python@3.10.

and if i understand everything correctly, running the brew link [PKG] it copies everything from the site-packages in the Cellar for shiboken and pyside to the opt site-packages for the python installation. hence why things worked when linking the above packages.

so not entirely sure i can add the .pth files for shiboken2 and pyside to pick up the installations without having to link the packages but hopefully this will be a step closer. and this will eventually help with homebrew CI builds. 🤞

a little q/a about the .pth files and site-packages dir

https://stackoverflow.com/a/7901603/708807

ipatch commented 2 years ago

feeling confident this issue should be resolved with the below commit

https://github.com/FreeCAD/homebrew-freecad/commit/addab68821f9c96272c24c1540edfd0cbb486953

if anybody experiences any issues feel to search the open issues and leave comment if something comes up or if your issue is completely separate, please open a new issue.

i believe adding the below lines to the freecad.rb formula resolved this issue at least in all my local testing.

https://github.com/FreeCAD/homebrew-freecad/blob/addab68821f9c96272c24c1540edfd0cbb486953/Formula/freecad.rb#L139-L141

ipatch commented 2 years ago

did a brew install freecad/freecad/freecad to test the bottle built via the CI. it appears some more work will be required for the FreeCAD GUI cmd to pick up on the runtime dependencies of shiboken2 and PySide2.

the quick fix is to manually create .pth file pointing the site-packages directory for both the shiboken2 and PySide2 installations. after creating those two files.

one quick test is to run the below cmd.

python3

should open the the python3 REPL that is installed via homebrew and which freecad relies upon, and then attempt to import both shiboken2 and pyside2 with the below commands

import shiboken2
import PySide2

got my bottle installation of freecad v0.20.1 going.

obviously this far from perfect, and more work will be required to get all this ironed out for future bottled releases.