Python unable to import module within library [closed]

非 Y 不嫁゛ 提交于 2020-12-13 03:30:50

问题


I'm trying to use the QSerialPort module of PyQt5. Everything I have found has indicated that QtSerial which contains QSerialPort should come with PyQt5. For example,

>>> from PyQt5 import QtSerial
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'QtSerial' from 'PyQt5' (/usr/lib/python3.8/site-packages/PyQt5/__init__.py)

I've tried installing PyQt5 from inside PyCharm, as well as on the command line with pip. I've tried upgrading pip and reinstalling PyQt5. I'm able to use other modules of PyQt5, for example PyQt5.QtWidgets imports without any problem. I've also tried installing qt5-serialport-595 and qt51-serialport from the AUR (I'm using Archlinux), to no avail.

I can see when I go to the command line and run $ pip list -v PyQt5 that PyQt5 is installed at /usr/lib/python3.8/site-packages/ and when I look there, I can see that the file /usr/lib/python3.8/site-packages/PyQt5/QtSerialPort.abi3.so exists. However I am also not able to import PyQt5.QtSerial as it is also not found, albeit with a slightly different message: ImportError: libQt5SerialPort.so.5: cannot open shared object file: No such file or directory

This is not caused by a typo in the import statement. I've tried pretty much every possible permutation of the letters Q and T and the words Serial and Port. How can I use the serial module of PyQt5?


回答1:


Based on this Archlinux forums post I ran pacman -Si python-pyqt5 which gave me a list of optional deps that included the line qt5-serialport: QtSerialPort so I used yay to install qt5-serialport. This is distinct from qt51-serialport, qt5-serialport-595, and in fact any of the AUR packages with serialport in the name that can be found by searching the AUR site, for some reason. Now when I use python on the command line, I can from PyQt5.QtSerialPort import QSerialPort with no error.

I should note that neither the package repo at https://pypi.python.org/simple which PyCharm is using to find installable packages, nor the searchable AUR listing, nor pip seems to show qt5-serialport as an option. So even though I got it downloaded and python can find it from the command-line, it still isn't being imported by PyCharm, which is a separate issue.



来源:https://stackoverflow.com/questions/64985940/python-unable-to-import-module-within-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!