Do0msDay Do0msDay - 1 year ago 62
Python Question

Use Python module on the runtime

import os
import sys


#try to import pip
except ImportError:
input('Could not install pip, please enter any key to quit this window.')

#install selenium
def install(package):
pip.main(['install', package])

if __name__ == '__main__':

When I run this script I get:

NameError: name 'pip' is not defined

It's like
doesn't import pip, how can I make it import pip?

When I ran this code it installed pip fine, also the
didn't throw any exception. I get this error when it tries to install selenium, because pip doesn't get imported in the
for some reason I think.

Answer Source

You should use the standard import pip unless you are trying to define the module to import dynamically. It will still raise ImportError if pip is not installed.