ModuleNotFoundError: No module named 'pytest'

新手上路,请多包涵

图片描述

import pytest


def test_main():
    assert 5!=5

if __name__ == "__main__":
    pytest.main()
    

在命令行又是可以正确找到虚拟环境pytest模块,在vscode里面运行提示找不到模块(vscode也是切换到虚拟环境得),报错如下:

[Running] python -u "d:\MyPytest\test_sample.py"
Traceback (most recent call last):
  File "d:\MyPytest\test_sample.py", line 1, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

[Done] exited with code=1 in 0.176 seconds
阅读 9.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进