Created
October 1, 2021 18:47
-
-
Save mchapman87501/e9823325ac83287d9ee3ee9175f1cfe3 to your computer and use it in GitHub Desktop.
Install PySide6 on macOS (Monterey) for M1 (Apple Silicon) Devices - h/t elliewhatever
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Many thanks to | |
# https://gist.githubusercontent.com/elliewhatever/adbe3fba37d747fb8b04af8f835d46d2/raw/61e2bd530eb434f7ea2f595262e1922cdd057f7c/PySide6.sh | |
# Assumes brew and python are installed | |
brew install qt@6 llvm cmake ninja git | |
# Setup environment relative to current directory - | |
# this eases building in an existing Python venv. | |
mkdir -p ./.pyside6; cd ./.pyside6 | |
BUILD_DIR=${PWD} | |
git clone --recursive https://code.qt.io/pyside/pyside-setup | |
# Change to match your Qt version: | |
QT_VER=6.1.3 | |
cd pyside-setup && git checkout ${QT_VER} | |
python -m venv testenv | |
source testenv/bin/activate | |
pip install -r requirements.txt | |
# Build PySide6 in environment | |
export CLANG_INSTALL_DIR=$(brew --prefix)/opt/llvm | |
CELLAR=${HOME}/homebrew/Cellar | |
# I'm not sure why this is necessary in my environment: | |
export QT_PLUGIN_PATH=${CELLAR}/qt/${QT_VER}/share/qt/plugins | |
python setup.py build --qmake=${CELLAR}/qt/${QT_VER}/bin/qmake --build-tests --ignore-git --parallel=8 | |
python setup.py install --qmake=${CELLAR}/qt/${QT_VER}/bin/qmake --build-tests --ignore-git --parallel=8 --reuse-build | |
# Function to copy PySide6 to new environment | |
# Note the case-sensitive .../site-packages/PySide6* -- your filesystem may vary. | |
echo 'function copy-pyside { | |
export PYSIDE=${BUILD_DIR}/pyside-setup/testenv | |
export VENV=$1 | |
rsync -av $PYSIDE/bin/shiboken6* $VENV/bin; rsync -av $PYSIDE/lib/python3.9/site-packages/shiboken6* $VENV/lib/python3.9/site-packages/ | |
rsync -av $PYSIDE/bin/pyside6-* $VENV/bin; rsync -av $PYSIDE/lib/python3.9/site-packages/PySide6* $VENV/lib/python3.9/site-packages/ | |
echo You may also need to: | |
echo export QT_PLUGIN_PATH=${CELLAR}/qt/${QT_VER}/share/qt/plugins | |
}' >> ~/.zshrc | |
# Manually copy packages to required environment (works for conda) | |
# export PYSIDE=~/.pyside6/testenv/ | |
# export VENV=PATH_TO_PROJECT/venv | |
# rsync -av $PYSIDE/bin/shiboken6* $VENV/bin | |
# rsync -av $PYSIDE/bin/pyside6-* .$VENV/bin | |
# rsync -av $PYSIDE/lib/python3.9/site-packages/PySide6* $VENV/lib/python3.9/site-packages/ | |
# rsync -av $PYSIDE/lib/python3.9/site-packages/shiboken6* $VENV/lib/python3.9/site-packages |
I'm not sure who maintains pyside-setup/build_scripts/main.py
, but they may be able to help: https://wiki.qt.io/Qt_for_Python#Community
Out of curiosity, which Python version/distribution produced the error? Was there any error output beyond the traceback, describing, e.g., the exception that triggered the traceback?
I had errors like "no member named XXX in the global namespace" during build, and I found a solution: https://forums.swift.org/t/is-anyone-else-getting-this-error-when-building-the-compiler-from-master-on-macos/36113
You could also build a *.whl after you built pyside:
python setup.py bdist_wheel --qmake=${QMAKE} --build-tests --ignore-git --parallel=${NCPU} --reuse-build
and install it to your venv:
pip
pip install ../relative/path/to/dist/shiboken6-6.2.1-6.2.1-cp310-cp310-macosx_12_0_arm64.whl
pip install ../relative/path/to/dist/PySide6-6.2.1-6.2.1-cp310-cp310-macosx_12_0_arm64.whl
poetry
poetry add ../relative/path/to/dist/shiboken6-6.2.1-6.2.1-cp310-cp310-macosx_12_0_arm64.whl
poetry add ../relative/path/to/dist/PySide6-6.2.1-6.2.1-cp310-cp310-macosx_12_0_arm64.whl
Your PySide, Python and macOS version may differ in the *.whl
outputs listed above.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got this error: