MetaData Generation Failed while installing PyQt5 - python-3.x

I have a similar problem as AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' for PyQt5 5.15.0. Most of the solutions proposed there is to install the latest version of pip. But I have the latest pip version (22.0.2) and it is still not working. I am trying to install it in MacOS 12.1, python version 3.8.9.
Command Output:
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: 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 "/Users/ashuadhikari/Library/Python/3.8/lib/python/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/ashuadhikari/Library/Python/3.8/lib/python/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/Users/ashuadhikari/Library/Python/3.8/lib/python/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/Users/ashuadhikari/Library/Python/3.8/lib/python/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/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/site-packages/sipbuild/api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "/private/var/folders/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/site-packages/sipbuild/project.py", line 587, in setup
self.apply_user_defaults(tool)
File "project.py", line 63, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/site-packages/sipbuild/project.py", line 234, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "/private/var/folders/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/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.
Note: Installing PyQt5 with brew worked but brew installed the latest python version as a dependency and I want to install PyQt5 inside my venv.

I was also having problems installing PyQt5 on an M1 Mac but found another alternative if you want to use venv without miniconda. Using brew to install python doesn't fix the pip errors when trying to install PyQt5 inside a venv.
The bug actually seems related to using the Python universal installer, and then there appears to be another bug with PyQt5 5.15.6.
First: install Python 3.9.13 MacOS Intel-only installer from python.org
After I did this I tried using pip to install the latest version of PyQt (5.15.6) inside the venv but pip flagged a hash mismatch:
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
PyQt5-Qt5>=5.15.2 from https://files.pythonhosted.org/packages/62/09/99a222b0360616250fb2e6003a54e43a2a06b0774f0f8d5daafb86a2c375/PyQt5_Qt5-5.15.2-py3-none-macosx_10_13_intel.whl#sha256=76980cd3d7ae87e3c7a33bfebfaee84448fd650bad6840471d6cae199b56e154 (from PyQt5):
Expected sha256 76980cd3d7ae87e3c7a33bfebfaee84448fd650bad6840471d6cae199b56e154
Got d97d141facbdb3af4f5593b5068fb1d57a2e01ccace3758b897636700f2a2640
So Second: use pip install PyQt5==5.15.5
That successfully allowed me to use venv as normal with PyQt5.

So people can find this answer outside of the comments :
Using Brew on macOS works, install both Python and PyQT5 from there, and be sure to change your python command to Brew's directory if you want it to work properly.
I have no idea why, but pip is currently broken on macOS (perhaps all platforms) when installing from python.org

1- check last updates python/pip version
2- install last version package (pip install pyqt6)
3- if you need run file QtDesigner just run main python , not ui script
example :
main.py:
from PyQt6 import uic
from PyQt6.QtWidgets import QApplication
Form, Window = uic.loadUiType("untitled.ui")
app = QApplication([])
window = Window()
form = Form()
form.setupUi(window)
window.show()
app.exec()
untitled.ui:
from PySide2.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,
QRect, QSize, QUrl, Qt)
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
QFontDatabase, QIcon, QLinearGradient, QPalette, QPainter, QPixmap,
QRadialGradient)
from PySide2.QtWidgets import *
class Ui_Frame(object):
def setupUi(self, Frame):
if Frame.objectName():
Frame.setObjectName(u"Frame")
Frame.resize(640, 480)
self.pushButton = QPushButton(Frame)
self.pushButton.setObjectName(u"pushButton")
self.pushButton.setGeometry(QRect(250, 210, 75, 23))
self.retranslateUi(Frame)
QMetaObject.connectSlotsByName(Frame)
# setupUi
def retranslateUi(self, Frame):
Frame.setWindowTitle(QCoreApplication.translate("Frame", u"Frame", None))
self.pushButton.setText(QCoreApplication.translate("Frame", u"PushButton", None))
# retranslateUi
and save you ui code in file untitled.ui (dont run ui file format .py)
;D

Related

Pip fails to install PyQt5 (any version) in macOS Monterey

I'm attempting to install PyQt5 through Pip/Pip3 in macOS Monterey. I've updated all Homebrew applications as well as all Pip installations using the recommended process. Every time I attempt to install the PyQt5 module, I recieve numerous errors. I've tried following some guides, and I've tried following related answers on this site. I've tried installing every version of this software from 5.12.0 to CURRENT. Here's the traceback:
% pip3 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: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [24 lines of output]
Querying qmake about your Qt installation...
/opt/homebrew/bin/qmake -query
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/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 "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/Library/Frameworks/Python.framework/Versions/3.9/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 "/Library/Frameworks/Python.framework/Versions/3.9/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 "/private/var/folders/5w/d_mjtj250fd4rrrt2g6pq95c0000gn/T/pip-build-env-rgde383o/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "/private/var/folders/5w/d_mjtj250fd4rrrt2g6pq95c0000gn/T/pip-build-env-rgde383o/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/5w/d_mjtj250fd4rrrt2g6pq95c0000gn/T/pip-build-env-rgde383o/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 610, in setup
self.update(tool)
File "project.py", line 160, in update
sipbuild.exceptions.UserException
[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.
Any suggestions? System: macOS Monterey 12.2.1, Apple Silicon M1 (aarch64)

ImportError: No module named '_tkinter', please install the python3-tk package

I've already gone through all the similar questions in this regard and tried the solutions proposed there. But I'm unable to get this error sorted out though my python3-tk package is installed in the proper virtualenv that I'm using for my project.
Though in my project, I don't use tkinter, when i try to run the file, I'm getting the following error related to the _tkinter module.
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/init.py", line 36, in
import _tkinter
ImportError: No module named '_tkinter'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/manuelanayantarajeyaraj/PycharmProjects/ChatbotWord2Vec/main.py", line 2, in
from matplotlib import pyplot as plt
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/init.py", line 62, in pylab_setup
[backend_name], 0)
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in
from . import tkagg # Paint image to Tk photo blitter extension.
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/tkagg.py", line 5, in
from six.moves import tkinter as Tk
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py", line 92, in get
result = self._resolve()
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py", line 82, in _import_module
import(name)
File "/usr/lib/python3.5/tkinter/init.py", line 38, in
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
Hence, I navigated to the location of my interpreter and created a virtualenv and installed the python3-tk package using the following
sudo apt-get install python3-tk
When I checked, all the packages seem to be up to date
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version (3.6.5-3~16.04.york0.2).
The following packages were automatically installed and are no longer required:
libappindicator1 libindicator7 libllvm4.0 linux-headers-4.10.0-28
linux-headers-4.10.0-28-generic linux-headers-4.13.0-36
linux-headers-4.13.0-36-generic linux-headers-4.13.0-37
linux-headers-4.13.0-37-generic linux-image-4.10.0-28-generic
linux-image-4.13.0-36-generic linux-image-4.13.0-37-generic
linux-image-extra-4.10.0-28-generic linux-image-extra-4.13.0-36-generic
linux-image-extra-4.13.0-37-generic linux-signed-image-4.10.0-28-generic
linux-signed-image-4.13.0-36-generic linux-signed-image-4.13.0-37-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 37 not upgraded.
But I'm still getting the same import error ImportError: No module named '_tkinter', please install the python3-tk package.
Any suggestions in this regard will be highly appreciated.
When you import matplotlib, it will probably be trying to use the tk backend as the default. If you didn't install tk, or you do not want to use it anywhere else in your project, then a possible solution would be to simply use a different backend:
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt
The message indicates that when you run sudo apt-get install python3-tk it tells you that tkinter is sintalled for Python3.6.5, but on the other hand, the ImportError is related to Python3.5. So I believe this should resolve your problem:
sudo apt-get install python3.5-tk

Install PyQt4 via conda for caffe model

When I try to run the SEC caffe model on from here: https://github.com/kolesman/SEC
I geht the error: ImportError: No module named PyQt4
python demo.py --model SEC.caffemodel --image /data/out/dataset/center/1475186965759787059.jpg --smooth --output result.png
Traceback (most recent call last):
File "demo.py", line 2, in <module>
import pylab
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/pylab.py", line 274, in <module>
from matplotlib.pyplot import *
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import QtCore
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 31, in <module>
from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py", line 137, in <module>
from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4
In this stackoverflow thread they just mention that you can run
conda install pyqt
which results in the following output:
conda install pyqt
Fetching package metadata .......
Solving package specifications: ..........
# All requested packages already installed.
# packages in environment at /home/ec2-user/anaconda2:
#
pyqt 5.6.0 py27_0
Which indicates that I have version 5.6 and not version 4. But I could not find any solution how to downgrade to pyqt4.
so you can Uninstall pyqt5 and download PyQt4 and installed manually
The second option is to modify the code and replace PyQt4 by pyqt5 just pay attention to one thing that the classes in pyqt5 are the same but the irritation is bit different so you may get that specific model doesn't exist in this case check on manual of pyqt5 and fix it
I hope my answer is clear
It looks like the latest version of anaconda forces install of pyqt5.6 over any pyqt build, which will be fatal for your applications. In a terminal, Try:
conda install --channel https://conda.anaconda.org/conda-forge pyqt
conda install -c anaconda pyqt=4.11.4
It will prompt to downgrade conda client. After that, it should be good.

Ubuntu 16.04 python3.5: PyAudio 0.2.9 or later is required (found version 0.2.8)

that's my first question here.
I have a problem with python3.5 and PyAudio on my Ubuntu 16.04:
What type of problem I have
Currently I'm writing on a program that uses the speech_recognition library in python.
And if I call my script (python3 processor.py), it says the following:
Traceback (most recent call last):
File "processor.py", line 143, in <module>
main()
File "processor.py", line 132, in main
with sp_reco.Microphone() as source:
File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 55, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 88, in get_pyaudio
raise AttributeError("PyAudio 0.2.9 or later is required (found version {0})".format(pyaudio.__version__))
AttributeError: PyAudio 0.2.9 or later is required (found version 0.2.8)
Checking existing pip3 modules with pip3 list gave me the following:
PyAudio (0.2.9)
And I don't know why speech_recognition says the found version is 0.2.8
And it works if I type python3 in the console and type in the shown python console import pyaudio
My script works fully, if I use the python command
Screenshot pip3 list

Spyder IDE fails to start on Windows 10 with Python 3.8 [duplicate]

This question already has answers here:
Jupyter Notebook with Python 3.8 - NotImplementedError
(4 answers)
Closed 3 years ago.
Note: this issue is fixed in Spyder 4.1.3!
(original question) checking out Python 3.8 (x64) on Windows 10, I got into trouble when trying to setup Spyder. Note: the issue was reproducible with a fresh Python installation on a clean Windows-10 system. However, no such issues on Linux (tested on debian / Mint19.x).
At first, everything went smooth during installation via pip install spyder.
error #1: pywin32
After starting Spyder, it said in the IPython console window:
Traceback (most recent call last):
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\spyder\plugins\ipythonconsole.py", line 1572, in create_kernel_manager_and_kernel_client
kernel_manager.start_kernel(stderr=stderr_handle)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\manager.py", line 240, in start_kernel
self.write_connection_file()
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\connect.py", line 470, in write_connection_file
self.connection_file, cfg = write_connection_file(self.connection_file,
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\connect.py", line 141, in write_connection_file
with secure_write(fname) as f:
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_core\paths.py", line 424, in secure_write
win32_restrict_file_to_user(fname)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_core\paths.py", line 359, in win32_restrict_file_to_user
import win32api
ImportError: DLL load failed while importing win32api: Das angegebene Modul wurde nicht gefunden.
I was able to fix the import error by running pywin32_postinstall.py -install from the scripts folder (from a cmd prompt with elevated rights). That copies pythoncom38.dll and pywintypes38.dll from \Lib\site-packages\pywin32_system32 to \windows\system32, see also here - however, I'd suggest to not modify system folders and use the option I put in my answer below.
error #2: tornado
However, now Spyder just freezes at the loading screen (logo displayed, saying something like "initializing main window")!
cloning the dev version of Spyder from https://github.com/spyder-ide/spyder.git and running it via python bootstrap.py --debug reveals the cause of the freeze:
2019-11-03 17:39:53,261 [ERROR] [tornado.application] -> Exception in callback functools.partial(<function ThreadedZMQSocketChannel.__init__.<locals>.setup_stream at 0x0000015E00B758B0>)
Traceback (most recent call last):
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
ret = callback()
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\jupyter_client\threaded.py", line 48, in setup_stream
self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 127, in __init__
self._init_io_state()
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 546, in _init_io_state
self.io_loop.add_handler(self.socket, self._handle_events, self.io_loop.READ)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError
...so it seems the import error caused by the Python 3.8 version of pywin32 is only one issue. There's also a problem related to tornado IO (web server), see here / here.
last checked with Python 3.8.2 (AMD64), Spyder 4.1.1. Please note that I am not using Anaconda. Use either conda or pip, not both.
Spyder 4.1.3 Update: The issue is fixed!
(Tested on Python 3.8.3rc1, tornado 6.0.4)
If you come here still experiencing similar startup issues with Spyder: the first thing to try I'd suggest upgrade to Spyder version >= 4.1.3.
older version of this answer
workaround, tornado issue:
Modify the file ...\Python38...\Lib\site-packages\tornado\platform\asyncio.py;
add
import sys
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
after the other import statements. Source: here on SO and also linked here. If I get this post on the tornado repo right, this is likely to be a pretty permanent workaround.
if also needed - workaround, pywin32 issue:
Modify the file ...\Python38\Lib\site-packages\jupyter_core\path.py;
add a line
import pywintypes
before import win32api in line 359. This modification is based on this post.

Resources