Python ModuleNotFoundError: No module named pytest














































Python ModuleNotFoundError: No module named pytest



python ModuleNotFoundError: No module named 'pytest'


Pytest is one of the most popular unit testing framework for python which is free and open source software. It is a command line tool which automatically finds test that you have written,runs the test and report the results.


Error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pytest'


SOLUTIONS:

1.FOR LINUX:

Initially create virtual environment and activate it before getting pytest installed.

Run the below commands to create and activate virtual environment.

$virtualenv *env_name*
$source *env_name*/bin/activate

Run the following command on terminal:

sudo pip3 install pytest           #for python3


Once the installation get completed, type 'import pytest' and check whether it is working.


2.FOR WINDOWS:

Run the following command in command prompt:

pip install pytest

wait until installation gets completed.


3.FOR ANACONDA:

Run the following command in Conda Prompt:

conda install pytest

Comments