2

I'm currently struggling to install a python package in a virtual environment. The set-up is the following: I have an M1 mac and with it, I have the system python installations located in /usr/bin/python (v 2.7.18) and usr/bin/python3 (v 3.8.9). Since I don't really like messing with these, I have installed pyenv and pyenv-virtualenv over brew. I installed Python 3.10.1 and created a virtual environment, let's call it test. I also added the following lines to .zshrc

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
PATH=$(pyenv root)/shims:$PATH 

(Most of this was done by following the explanations on the github page of pyenv).

I'm now trying to install some packages in test. numpy, scipy, etc worked perfectly but when I try to install PyQt5 with pip I get an error.

❯ pip install PyQt5
Collecting PyQt5
  Using cached PyQt5-5.15.6.tar.gz (3.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/UserName/.pyenv/versions/3.10.1/envs/simpy/bin/python3.10 /Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/tmp2ofsepfy
       cwd: /private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-install-5rev2dd7/pyqt5_3892c9f35c2f41a186bcd36237d536d7
  Complete output (29 lines):
  Traceback (most recent call last):
    File "/Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 156, in prepare_metadata_for_build_wheel
      hook = backend.prepare_metadata_for_build_wheel
  AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
      main()
    File "/Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 160, in prepare_metadata_for_build_wheel
      whl_basename = backend.build_wheel(metadata_directory, config_settings)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/sipbuild/api.py", line 51, in build_wheel
      project = AbstractProject.bootstrap('pep517')
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
      project.setup(pyproject, tool, tool_description)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/sipbuild/project.py", line 587, in setup
      self.apply_user_defaults(tool)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-install-5rev2dd7/pyqt5_3892c9f35c2f41a186bcd36237d536d7/project.py", line 63, in apply_user_defaults
      super().apply_user_defaults(tool)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
      super().apply_user_defaults(tool)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/sipbuild/project.py", line 234, in apply_user_defaults
      self.builder.apply_user_defaults(tool)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/pyqtbuild/builder.py", line 67, in apply_user_defaults
      raise PyProjectOptionException('qmake',
  sipbuild.pyproject.PyProjectOptionException
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/3b/27/fd81188a35f37be9b3b4c2db1654d9439d1418823916fe702ac3658c9c41/PyQt5-5.15.6.tar.gz#sha256=80343bcab95ffba619f2ed2467fd828ffeb0a251ad7225be5fc06dcc333af452 (from https://pypi.org/simple/pyqt5/) (requires-python:>=3.6). Command errored out with exit status 1: /Users/UserName/.pyenv/versions/3.10.1/envs/simpy/bin/python3.10 /Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/tmp2ofsepfy Check the logs for full command output.

What exactly is going on here? Is this related to the m1 chip or the set-up of the virtual environment? How can I fix this?


On the suggestion of @pedro_bb7 I downgraded Python to 3.9.9 (since PyQt5 is not yet ready for Python 3.10.0) and also tried installing an older versions (5.14.1/2/, 5.15.0/1/2/3/4/5/6) of PyQt5 over the command

❯ pip install PyQt5==5.14.0
Collecting PyQt5==5.14.0
  Using cached PyQt5-5.14.0.tar.gz (3.2 MB)
ERROR: PyQt5==5.14.0 from https://files.pythonhosted.org/packages/7c/5b/e760ec4f868cb77cee45b4554bf15d3fe6972176e89c4e3faac941213694/PyQt5-5.14.0.tar.gz#sha256=0145a6b7de15756366decb736c349a0cb510d706c83fda5b8cd9e0557bc1da72 has a pyproject.toml file that does not comply with PEP 518: 'build-system.requires' contains an invalid requirement: 'sip >=5.0.1 <6'

As you can see, still no luck...

Sito
  • 494
  • 10
  • 29

2 Answers2

0

Probably you need to upgrade pip to the latest, as suggested:

pip install --upgrade pip

https://stackoverflow.com/a/67606704/11381650

EDIT: it's not yet supported for Python 3.10 as you can see:

https://github.com/altendky/pyqt-tools/issues/98

and try different versions of PyQt, could you try 5.14.0 for Python 3.9?

https://stackoverflow.com/a/59797479/11381650

pedro_bb7
  • 1,601
  • 3
  • 12
  • 28
  • Already done and does not work. Pip is at version 21.3.1 – Sito Jan 10 '22 at 10:27
  • How about PyQt version? Maybe you need to specify one that works for the Python version you are using.. – pedro_bb7 Jan 10 '22 at 10:45
  • I just tried it with Python 3.9.9 and I get the same error... – Sito Jan 10 '22 at 11:06
  • added more one step to my answer – pedro_bb7 Jan 10 '22 at 11:13
  • Still no luck.. The error message is: `❯ pip install PyQt5==5.14.0 Collecting PyQt5==5.14.0 Using cached PyQt5-5.14.0.tar.gz (3.2 MB) ERROR: PyQt5==5.14.0 from https://files.pythonhosted.org/packages/7c/5b/e760ec4f868cb77cee45b4554bf15d3fe6972176e89c4e3faac941213694/PyQt5-5.14.0.tar.gz#sha256=0145a6b7de15756366decb736c349a0cb510d706c83fda5b8cd9e0557bc1da72 has a pyproject.toml file that does not comply with PEP 518: 'build-system.requires' contains an invalid requirement: 'sip >=5.0.1 <6'` – Sito Jan 10 '22 at 11:14
  • Are you trying to install it on a Raspberry? Anyways, try `5.14.1` – pedro_bb7 Jan 10 '22 at 11:15
  • Nope, macOS... Newst version. – Sito Jan 10 '22 at 11:16
  • 1
    Tried 5.14.1/2/, 5.15.0/1/2/3/4/5/6 and all don't work. The error message can be found [here](https://codedump.xyz/ruby/YdwWK7N_1bylw7zw). – Sito Jan 10 '22 at 11:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240919/discussion-between-pedro-bb7-and-sito). – pedro_bb7 Jan 10 '22 at 11:27
  • Is there any update? Wondering if you were able to resolve this as I'm having the same problem. – morejanus Feb 01 '22 at 00:35
  • 1
    @morejanus Nope, not really. You can install `PyQt5` over `homebrew` and should be able to use it with `/opt/homebrew/bin/python3`. But I still can't get it to run in a virtual environment. – Sito Feb 01 '22 at 15:29
0

Method 1: Use rosetta terminal, install pyqt5

Youtube link to open rosetta terminal on Mac m1 https://www.youtube.com/watch?v=9W8rTTE1WEA

And then use pip to install under your virtual enviorment

 pip install PyQt5

Method 2: Running under pyqt6

Like LemurPwned said in How can I run pyqt5 on my Mac with M1chip (ppc64el architecture)?

pyqt6 is now easily installable via pip on M1/M2 Macs

You can install that via

pip install PyQt6
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 05 '23 at 20:38