import os
import sys
#run get-pip.py
os.system("python get-pip.py")
#try to import pip
try:
__import__('pip')
except ImportError:
input('Could not install pip, please enter any key to quit this window.')
sys.exit()
#install selenium
def install(package):
pip.main(['install', package])
if __name__ == '__main__':
install('selenium')
When I run this script I get:
NameError: name 'pip' is not defined
It's like __import__('pip') doesn't import pip, how can I make it import pip?
When I ran this code it installed pip fine, also the try didn't throw any exception. I get this error when it tries to install selenium, because pip doesn't get imported in the try for some reason I think.
import pip?import pipwould still raise ImportError if pip was not installed. The only reason to use__import__()is if you're trying to import something dynamically, which you're not.