How can I run pyqt5 on my Mac with M1chip (ppc64el architecture)?
Asked Answered
S

13

28

Now. When I run it. The error comes

ImportError: dlopen(/Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so, 2): no suitable image found. Did find: /Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so: mach-o, but wrong architecture /Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so: mach-o, but wrong architecture

Signpost answered 26/1, 2021 at 12:12 Comment(2)
Apparently, the M1 chips are so new that Python itself doesn't know what is up with them. I heard about something called "Rosetta" that allows you to run things like on Intel Macs. Try that?Care
PyQt6 supports apple silicon starting from version 6.2 https://mcmap.net/q/282380/-how-to-install-pyqt5-on-m1-arm64-architectureTry
B
52

After hours of trial and error, I was finally able to solve this. My successful configuration is:

  1. Open terminal with Rosetta 2 (https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g)
  2. Use non-homebrew python (mine was in /usr/bin/python3) to create virtual environment
/usr/bin/python3 -m venv env
source env/bin/activate
  1. Upgrade pip
pip install --upgrade pip
  1. Install PyQt5
pip install PyQt5
Bimetallism answered 18/6, 2021 at 16:16 Comment(8)
Running the Terminal in Rosetta mode worked for me - ThanksAssiduous
Was trying to get this working from a day! damn, thanks mate :)Jerol
This worked for me. Why doesn't python installed via homebrew work?Klansman
If it’s installed with Rosetta, will it still work with native M1 python? I just got my m1 MacBook Pro a few days ago so apologies if this is a dumb question.Aromaticity
Please give this guy a medal.Coneflower
@Aromaticity I was thinking the same. These steps can be followed; although if you do not want to always have your terminal open in Rosetta, or if you just have some one-off commands, you can prepend arch -x86_64 to any command that needs Rosetta. So, my steps would have been: virtualenv env (or whatever env you like), source env/bin/activate, arch -x86_64 pip install PyQt5, and then when you want to run whatever program you are writing, arch x86_64 my_wicket_program.pySewing
The key for me was step 2. If you use the brew version it still breaks.Uriia
Thanks @AxelJacobsen, this saved my lot of time. arch -x86_64 is important here.Tristantristas
C
18

I needed PyQt5 as a dependency for a Python library and this worked for me. See original post here.

brew install pyqt5
echo 'export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/pyqt@5/5.15.4_1/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Calomel answered 9/12, 2021 at 20:24 Comment(1)
I also added: export PYTHONPATH=/opt/homebrew/Cellar/pyqt@5/5.15.7/lib/python3.9/site-packages to my ~/.zshrcVariform
M
14

What I ended up doing specifically for pyqt5 was:

brew install pyqt@5

I think for versions 4 and 6 this may work as well. When I went simply brew install pyqt that didn't work unfortunately.

note this is M1 Macbook only

One other thing to try as things settle down with M1s is to try pip3 install pyqt5 in a terminal launched in Rosetta mode (left click -> Get Info -> Open in Rosetta)

Edit (Nov 2022)

It seems that if you don't specifically need pyqt5, pyqt6 is now easily installable via pip on M1/M2 Macs.

python -m pip install pyqt6
Missend answered 2/6, 2021 at 21:7 Comment(4)
I'm installing a package that uses PyQt5. I was able to run brew install pyqt@5 but the installation still fails on Collecting PyQt5==5.15.2Eutrophic
@JeffBezos perhaps removing that requirement from package dependencies would skip installing it? It may work with the version you installed via brew.Missend
error: metadata-generation-failedCertainly
but still, when I run pip list --outdated | awk '{print $1}' | xargs -n1 sh -c 'pip install -U "$@" | tee -a upgrade.log' sh to update all packages, it looks for pyqt5! which stuck on Preparing metadata (pyproject.toml): startedIndreetloire
Z
6

I was hoping to install pyqt5 on my M1 mac without Rosetta. I was using it as a dependency of another project that I wanted to install in a venv which requires pyqt5 and was not installable via pipx (urh).

Unfortunately, there currently are no compatible wheels (curl --silent "https://pypi.org/pypi/PyQt5/json" | grep -i arm64), and attempting to install on 3.10 fails with AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'

Thankfully, the homebrew installation of pyqt5 is compiled for arm64 and works well.

My steps were:

$ # Install pyqt5 via homebrew
$ brew install pyqt@5
$ # Note that it's installed in python3.9, not 3.10
$ brew cat pyqt@5 | grep 'depends_on.*python'
  depends_on "[email protected]"
$ # Make a python3.9 virtualenv with access to the system's site-packages
$ /opt/homebrew/bin/python3.9 -m venv --system-site-packages .venv
$ source .venv/bin/activate

At this point I was able to install urh into the virtualenv, using the arm64-compiled pyqt5 from hombrew, without neededing Rosetta (and without needing to further "pollute" my system site-packages), and it runs as expected (since the question was about running).

Zoroastrian answered 24/5, 2022 at 13:19 Comment(2)
This one worked for me using python3.9, trying to pip3.9 install office365. I think --system-site-packages may have been key here.Henryk
this is the only one that worked for me and it was the easiest once as well. Should be marked as the accepted answer.Gramercy
C
4

Try installing the pyqt under the ARM architecture as below

arch -arm64 brew install pyqt

Coincident answered 2/5, 2021 at 11:4 Comment(0)
W
2

You can use it from homebrew, this is the only way I found it working on Mac M1.

First:

  brew install pyqt@5

Then:

brew --cellar
brew link --overwrite python

Then you must create/add an alias for python and put it in your .zprofile (Located in Users/username folder, if you press Shift+command+.

This must point to your homebrew python installation location.

alias python ='opt/homebrew/bin/python3'

That way it will link python with your homebrew python and you can run python test.py from terminal (Where your python files are located). No matter how I tried with pip install, it just shown error and did not work.

Wreak answered 20/11, 2021 at 17:16 Comment(0)
C
2

I had to install PyQt5==5.15.6on my MacM1 into an existing virtual environment.

It did not work using all the methods described here.

So, what I did is :

  1. Open the terminal in rosetta mode
  2. Navigate to my project and activate the virtual environment source venv/bin/activate
  3. Install the package : pip install PyQt5==5.15.6
  4. Open a regular terminal into my project and make sure everything was installed as per the requirements.txt : pip install -r requirements.txt

Everything is running smoothly, now.

Constable answered 15/6, 2022 at 16:52 Comment(0)
P
1

In my case it's work: arch -x86_64 brew install pyqt And all required pyqt start from arch -x86_64 or start from rosetta (through emulator).

Prolate answered 9/11, 2021 at 9:56 Comment(0)
M
1

I wanted to run PyQt5 under virtual environment with Python3.6.
The following procedures worked for me.

My settings are MBA M1 2020, macOS 11.3.1, and

pyenv versions
>   system
> * 3.6.15
pip -V
> pip 21.3.1 from /Users/username/.pyenv/versions/3.6.15/lib/python3.6/site-packages/pip (python 3.6)

Then simply run:

pip install pyqt5-sip
pip install pyqt5

on the terminal (default one, not the one with Rosetta 2).

Mnemonic answered 18/4, 2022 at 19:34 Comment(0)
J
1

If anyone is still having the same problem with installation of PyQT5, I would suggest you to rather lock your focus on PySide6. It is 99% similar to PyQT5 and works well with MacBook m1.

I've been digging the Internet for hours hoping to find the solution but it appears that PyQT5 and PyQT5-tools modules are somewhat broken on MacBook M1 when it comes to downloading them.

Joon answered 30/6, 2022 at 17:40 Comment(0)
T
1

I was struggling with installing PyQt5 on M1 mac with MacOS 12.6 (Monterey) inside a virtual environment (using python 3.9). The final solution that worked for me was to use conda for creating and activating the virtual environment.

conda create --name venv python=3.9 conda activate venv

And then simply using conda to install PyQt5 as part of the pyqt package.

conda install pyqt

Tigrinya answered 27/9, 2022 at 14:25 Comment(0)
T
1

PyQt6 is out now and supports apple silicon:

https://mcmap.net/q/282380/-how-to-install-pyqt5-on-m1-arm64-architecture

No conda support, but pip install is working fine:

python -m pip install PyQt6
Try answered 24/1, 2023 at 17:35 Comment(0)
B
0

You should just upgrade to PySide6. It's the official library, and it was actually easier for me than upgrading to PyQT6 since we have a pyside6-rcc command so you can use your .qrc files as is. PyQT6 dropped pyrcc6.

Bisector answered 2/7, 2023 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.