如何解决Python 3.8 pytest-qt ModuleNotFoundError:没有名为“ PyQt4”的模块
我已经在安装了python 3.6的Linux mint 19上创建了我的项目。我将pytest
与pytest-qt
结合使用来测试我的应用程序,它是一个PyQt5程序。
然后,我已经更新到Linux mint20。但是,在那里安装了python 3.8而不是3.6。我不知道它是否相关,但是现在我无法运行我的测试套件,当我在终端中键入pytest
时,它会提供以下输出:
Traceback (most recent call last):
File "/home/kotlin/.local/bin/pytest",line 8,in <module>
sys.exit(console_main())
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py",line 187,in console_main
code = main()
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py",line 143,in main
config = _prepareconfig(args,plugins)
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py",line 318,in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/hooks.py",line 286,in __call__
return self._hookexec(self,self.get_hookimpls(),kwargs)
File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/manager.py",line 93,in _hookexec
return self._inner_hookexec(hook,methods,line 84,in <lambda>
self._inner_hookexec = lambda hook,kwargs: hook.multicall(
File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/callers.py",line 203,in _multicall
gen.send(outcome)
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/helpconfig.py",line 100,in pytest_cmdline_parse
config = outcome.get_result() # type: Config
File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/callers.py",line 80,in get_result
raise ex[1].with_traceback(ex[2])
File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/callers.py",in _multicall
res = hook_impl.function(*args)
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py",line 1003,in pytest_cmdline_parse
self.parse(args)
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py",line 1280,in parse
self._preparse(args,addopts=addopts)
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py",line 1172,in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/manager.py",line 299,in load_setuptools_entrypoints
plugin = ep.load()
File "/usr/lib/python3.8/importlib/metadata.py",line 77,in load
module = import_module(match.group('module'))
File "/usr/lib/python3.8/importlib/__init__.py",line 127,in import_module
return _bootstrap._gcd_import(name[level:],package,level)
File "<frozen importlib._bootstrap>",line 1014,in _gcd_import
File "<frozen importlib._bootstrap>",line 991,in _find_and_load
File "<frozen importlib._bootstrap>",line 975,in _find_and_load_unlocked
File "<frozen importlib._bootstrap>",line 671,in _load_unlocked
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/assertion/rewrite.py",line 171,in exec_module
exec(co,module.__dict__)
File "/home/kotlin/.local/lib/python3.8/site-packages/pytestqt/plugin.py",line 7,in <module>
from pytestqt.qt_compat import QtCore,QtGui,QtTest
File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/assertion/rewrite.py",module.__dict__)
File "/home/kotlin/.local/lib/python3.8/site-packages/pytestqt/qt_compat.py",line 31,in <module>
import PyQt4.QtCore as _QtCore
ModuleNotFoundError: No module named 'PyQt4'
最后它说ModuleNotFoundError: No module named 'PyQt4'
,但我什至不使用PyQt4,而是使用PyQt5。
我同时安装了pytest
和pytest-qt
。该程序本身可以正常运行。
谢谢。
解决方法
这部分错误消息:
File "/home/kotlin/.local/lib/python3.8/site-packages/pytestqt/qt_compat.py",line 31,in <module>
import PyQt4.QtCore as _QtCore
ModuleNotFoundError: No module named 'PyQt4'
提示问题-使用的qt-pytest
版本仍然引用PyQt4
,而current version早些时候已删除了这些引用-意味着已安装的python-qt
版本是过时的。可以使用
pip3 install -U pytest-qt
如评论中所述。尚不清楚为什么首先要安装旧版本-一种可能是其他软件包已经安装了旧版本,可以通过pip
(没有update
选项安装)在这种情况下什么也不做。版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。