I encountered a ModuleNotFoundError: No module named ‘pytest’ after installing the pytest module in a virtual environment.
Although I installed pytest outside the virtual environment and can use it normally with Python, I am getting this error when running the following code inside the virtual environment:
import pytest
def test_main():
assert 5 != 5
if __name__ == "__main__":
pytest.main()
The error message is:
[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.185 seconds
How can I resolve this issue?