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

44.6k Views Asked by At

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

13

There are 13 best solutions below

0
On

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).

0
On

Try installing the pyqt under the ARM architecture as below

arch -arm64 brew install pyqt

4
On

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
2
On

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).

0
On

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.

8
On

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
0
On

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.

0
On

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.

1
On

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
0
On

PyQt6 is out now and supports apple silicon:

https://stackoverflow.com/a/75224682/19486832

No conda support, but pip install is working fine:

python -m pip install PyQt6
0
On

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.

0
On

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).

0
On

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