changeset 650:9cb40c01c10a

illustrate downloading a package and rerunning via exec
author Jeff Hammel <k0scist@gmail.com>
date Mon, 24 Mar 2014 13:54:24 -0700
parents fbfc02ea7d8e
children 66a7729aa049
files python/example/install_and_exec.py
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/example/install_and_exec.py	Mon Mar 24 13:54:24 2014 -0700
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+illustrates installation and execution following installation
+"""
+
+import os
+import subprocess
+import sys
+
+here = os.path.dirname(os.path.realpath(__file__))
+
+try:
+    import gnupg
+    print ("gnupg installed")
+except ImportError:
+    print ("gnupg not installed")
+    subprocess.check_call(['pip', 'install', 'gnupg'])
+    args = [sys.executable] + sys.argv
+    os.execl(sys.executable, *args)