简体   繁体   English

Python 3.8 pytest-qt ModuleNotFoundError:没有名为“PyQt4”的模块

[英]Python 3.8 pytest-qt ModuleNotFoundError: No module named 'PyQt4'

I have created my project on Linux mint 19 with python 3.6 installed.我已经在安装了 python 3.6 的 Linux mint 19 上创建了我的项目。 I used pytest in conjunction with pytest-qt to test my app which is a PyQt5 program.我将pytestpytest-qt结合使用来测试我的应用程序,它是一个 PyQt5 程序。

Then, I've updated to Linux mint 20. However python 3.8 is installed there instead of 3.6.然后,我已经更新到 Linux mint 20。但是 python 3.8 安装在那里而不是 3.6。 I don't know whether it's related or not but now I can't run my test suite anymore, when I type pytest in terminal it gives me the following output:我不知道它是否相关,但现在我无法再运行我的测试套件,当我在终端中输入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, kwargs)
  File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, 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", line 187, 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", line 171, in exec_module
    exec(co, 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'

At the end it says ModuleNotFoundError: No module named 'PyQt4' but I don't even use PyQt4, I use PyQt5 instead.最后它说ModuleNotFoundError: No module named 'PyQt4'但我什至不使用 PyQt4,而是使用 PyQt5。

I have pytest and pytest-qt both installed.我已经安装了pytestpytest-qt The program itself works properly.程序本身运行正常。

Thanks.谢谢。

This part of the error message:这部分错误信息:

  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'

hints at the problem - the used qt-pytest version still references PyQt4 , while the current version has these references removed some time ago -- meaning the installed python-qt version is outdated.提示问题 - 使用的qt-pytest版本仍然引用PyQt4 ,而当前版本在一段时间前删除了这些引用 - 这意味着安装的python-qt版本已过时。 The version can be updated using可以使用更新版本

pip3 install -U pytest-qt

as mentioned in the comments.如评论中所述。 It is still unclear why an old version was installed in the first place - one possibility is that an old version already had been installed by some other package, installing it via pip (without the update option) would not do anything in this case.目前尚不清楚为什么首先安装旧版本 - 一种可能性是旧版本已经由其他软件包安装,在这种情况下通过pip (没有update选项)安装它不会做任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM