I have got the answer for "how, inside a python script can I install packages using pip?" which is;
from pip._internal import main as pipmain
pipmain(['install', 'package-name'])
For backwards compatibility you can use:
try:
from pip import main as pipmain
except ImportError:
from pip._internal import main as pipmain
But if I run it,I get some output showing download information and progress. Is there any way to not get that(Make the code to just do its business behind the curtain)?
I tried a suggested answer(Below), but it doesnt seem to work.
import sys,os
def blockPrint():
sys.stdout = open(os.devnull, 'w')
def enablePrint():
sys.stdout = sys.__stdout__
blockPrint()
try:
from pip import main as pipmain
except ImportError:
from pip._internal import main as pipmain
pipmain(['install', 'numpy'])
enablePrint()
print("hello")