I’m trying to install and import the modules who are missing in a python script before it shows error.
try:
import matplotlib
import numpy
except ImportError as e:
import os
module = e.name
os.system(‘pip install ‘+ module)
import module
The errors I get : ModuleNotFound : No module named “matplotlib”
import module ModuleNotFoundError: No module named “module”
Although the module gets installed correctly, when I rerun it again, the script recognizes the installed modules and works fine. Any idea what it could be?