7

I've just built PyQt5 in a pyenv virtualenv with python 3.6.3 on OpenSUSE leap, the build went fine, but when I import

>>> from PyQt5 import QtCore
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: PyCapsule_GetPointer called with incorrect name

I can import PyQt5, but then I cannot use the modules under it

>>> import PyQt5
>>> PyQt5.QtCore
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'PyQt5' has no attribute 'QtCore'

I've read here that the cause could be another sip on the system for example of a PyQt4 installation, I tried to uninstall PyQt4 from the package manager but it didn't help.

I have no idea what to do, any ideas?

If I install the python3-qt5 package and use the system python it works

Edit:

I had the same problem with PyQt4 on another machine on OpenSUSE Leap 15, the solution was to configure sip with:

python configure.py --sip-module PyQt4.sip --no-dist-info --no-tools

as stated in the PyQt4 doc

Pedru
  • 1,430
  • 1
  • 14
  • 32

5 Answers5

3

OK so this was pretty easy actually, as stated in the doc (PyQt4, PyQt5), SIP must be configured with the --sip-module option, so for PyQt5 I did:

python configure.py --sip-module PyQt5.sip --no-tools

and for PyQt4:

python configure.py --sip-module PyQt4.sip --no-tools

This applies for PyQt >= 4.12.2 and PyQt >= 5.11

EDIT: PyQt5 now has the so called PyQt-builder, see the PyQt5 doc

Pedru
  • 1,430
  • 1
  • 14
  • 32
  • I am facing a similar problem. Could you pls explain a bit more about your solution? What is this configure.py file? –  Feb 11 '19 at 12:29
  • 1
    calling `configure.py` is part of the [building process](https://riverbankcomputing.com/static/Docs/PyQt5/installation.html#building-and-installing-from-source), this applies only if you build PyQt yourself – Pedru Feb 14 '19 at 10:33
  • 1
    I have the same issue but the suggested configuration throws the following error: `python: can't open file 'configure.py': [Errno 2] No such file or directory`. Based on a suggestion about this last part I tried to update pip setuptools with `pip install --upgrade setuptools` but it did not help. – nocibambi Apr 09 '19 at 09:10
  • 1
    Hm I installed via pip3: pip3 install PyQt5-sip pip3 install PyQt5 -> How can I configure now? – sqp_125 Jun 20 '19 at 06:39
  • Broken link to PyQt5 documentation – jberrio Feb 26 '20 at 04:42
1

So for me the this error occured when I tried to use pyuic5.

In my case I just had to activate my virtual_environment and then it worked.

sqp_125
  • 538
  • 6
  • 21
1

For posterity, I had this error for quite a while in my PyQt5 application because I was using two custom libraries (libArcus and libSavitar) that also use SIP to compile Python bindings. This was eventually fixed by making sure that my custom libraries (using a newer SIP version) were imported first, before PyQt5:

https://github.com/Ultimaker/Cura/blob/b20a349b4454d08e34b3c3ea3f537a380e4c7696/cura_app.py#L140-L141

This worked. However when running the application through PyCharm's debugger I still got the same error. Today I figured out that PyCharm has an option to "enable PyQt5 compatibility" with a certain PyQt5 version. Disabling this option under Settings -> Debugger -> PyQt compatible fixed this.

Ghostkeeper
  • 2,830
  • 1
  • 15
  • 27
  • I always wondered what that option does, activating or deactivating it sometimes fixes things. – Pedru Aug 27 '19 at 12:44
0

Is your application importing both PyQt4 and 5?

I've seen the first error on windows with this:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Executable: D:\Python37\python.exe
>>> from PyQt5 import QtWidgets
>>> from PyQt4 import QtGui, QtCore
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: PyCapsule_GetPointer called with incorrect name
NateTheGrate
  • 590
  • 3
  • 11
0

I downgraded the PyQt5 to 5.7.1 and it worked for me.

double-beep
  • 5,031
  • 17
  • 33
  • 41
PritamJ
  • 337
  • 4
  • 10