Confirmation when installing with pip globally
Question: Sometimes when working with Python projects one can forget to activate a
virtual environment.

Is there a way to get an explicit confirmation when installing Python modules
with pip to the global scope instead of a virtual environment?


Answer: You can try to wrap `pip install`, e.g.:

    
    
    import pip
    
    def install(package):
        pip.main(['install', package])
    
    # Example
    if __name__ == '__main__':
        if not hasattr(sys, 'real_prefix'):
            # replace this with your confirmation callback
            print('Warning! installing in global scope!')
        install('argh')
    

Sources:

[Installing python module within
code](http://stackoverflow.com/a/15950647/165753)

[Python: Determine if running inside
virtualenv](http://stackoverflow.com/a/1883251/165753)

