Skip to content

Instantly share code, notes, and snippets.

@blip2
Created March 2, 2018 06:22
Show Gist options
  • Save blip2/c4b0c81b91c042f08c90fd83a4f3c0f9 to your computer and use it in GitHub Desktop.
Save blip2/c4b0c81b91c042f08c90fd83a4f3c0f9 to your computer and use it in GitHub Desktop.
import os
import pip
import ctypes, sys
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
os.chdir(os.path.dirname(os.path.realpath(__file__)))
def install(package):
pip.main(['install', package])
if __name__ == '__main__':
if is_admin():
fh = open('requirements.txt')
for line in fh:
install(line)
fh.close()
else:
ctypes.windll.shell32.ShellExecuteW(
None, "runas", sys.executable,
os.path.realpath(__file__), None, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment