TheCrazySwede
TheCrazySwede

Reputation: 123

PyQt5 Modules not Found?

This is a complete fresh install of MacOS!

Platform:

Apple MacBook Air - M1
MacOS Monterey

Package Info:

Homebrew: 3.3.14
pip: 22.0.3
Python: 3.9.10 (installed via 'brew install python')
Latest-Xcode

My $PATH environment:

/opt/homebrew/bin
/opt/homebrew/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

I tried adding a combination of these to my $PATH, to no avail:

/opt/homebrew/lib/python3.9/site-packages
/opt/homebrew/Cellar/pyqt@5/5.15.6/lib/python3.9/site-packages/PyQt5
/opt/homebrew/lib/python3.9/site-packages/PyQt5
/opt/homebrew/opt/pyqt@5/5.15.6/bin
/opt/homebrew/opt/qt@5/5.15.6/bin

What I want to do:

pip install pyqt5

What happens when I try:

  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [29 lines of output]
      Traceback (most recent call last):
        File "/opt/homebrew/lib/python3.9/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 "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/opt/homebrew/lib/python3.9/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 "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/api.py", line 51, in build_wheel
          project = AbstractProject.bootstrap('pep517')
        File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/project.py", line 594, in setup
          self.apply_user_defaults(tool)
        File "project.py", line 63, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/project.py", line 241, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyqtbuild/builder.py", line 67, in apply_user_defaults
          raise PyProjectOptionException('qmake',
      sipbuild.pyproject.PyProjectOptionException
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

If I install it this way, I get no errors:

brew install pyqt@5

But my VS Code shows up like this, and none of submodules work:

enter image description here

My program used to work just fine, but I had recently installed Python 3.10 and have since uninstalled it. Ever since the new Python install, I've had this issue. Not sure how to tackle this. Thank you!

Upvotes: 3

Views: 4604

Answers (3)

remiel0731
remiel0731

Reputation: 1

my install setup is

1.brew install qt
2.brew install libxml2

reference by TheCrazySwede answer ↓↓↓

3.brew install pyqt5 enter image description here

4.brew cleanup pyqt@5

5.echo 'export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"' >> ~/.zshrc

6.echo 'export PATH="/opt/homebrew/opt/pyqt@5/5.15.4_1/bin:$PATH"' >> ~/.zshrc

7.source ~/.zshrc

8.pip3 install pyqt5-sip

9.pip3 install pyqt5 enter image description here enter image description here

10.pip3 install lxml

11.make qt5py3

I hope can help for you.

Upvotes: 0

Monir Khan
Monir Khan

Reputation: 19

I had the issue as yours. I solve with the following command.

pip3 install pyqt5

Upvotes: 0

TheCrazySwede
TheCrazySwede

Reputation: 123

I've asked this question a number of different ways in a number of different places; none of the suggested answers work for me.

The closest thing to an answer that I got to was this: https://www.zhihu.com/question/437075754/answer/1993415429

If you're unable to read it, it suggests this:

Pre-work, install homebrew, python 3.9.

First enter in the terminal:

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

Then, copy all the contents of /opt/homebrew/Cellar/pyqt@5/5.15.4_1/lib/python3.9/site-packages to lib/python3.9/site-packages folder. If your homebrew installation address and python installation address are not the default, you need to modify these two addresses.

Finally, try it in python

import PyQt5

But this didn't work for me, either.

In the end, I ended up just installing PyQt6:

pip install PyQt6

The install completed without any errors. Now I am working on updating my code. Hopefully this will be useful for someone else coming here from an angry Google search. Code on, my friends.

Upvotes: 2

Related Questions