'Installed module could not be found in python environment

I have a python environment and need to work with matplotlib module. It is installed in env and when I use command pip list, it is shown in modules name list. But when I want to import it in my script or calling command python -m matplotlib module could not be found in env:

"No module named matplotlib.__main__; 'matplotlib' is a package and cannot be directly executed"



Solution 1:[1]

Although some python packages can be run as standalone program (with python -m <the_package_name>) this does not apply to all python packages. In order to be run with the -m flag, the package must explicitly support this. matplotlib or e.g. also numpy do not support this. You can use functions and classes of these packages by importing them into another python script with the import statement.

import matplotlib

or

import numpy

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jakob Stark