1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/python/virtualenv/virtualenv_embedded/activate_this.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,34 @@ 1.4 +"""By using execfile(this_file, dict(__file__=this_file)) you will 1.5 +activate this virtualenv environment. 1.6 + 1.7 +This can be used when you must use an existing Python interpreter, not 1.8 +the virtualenv bin/python 1.9 +""" 1.10 + 1.11 +try: 1.12 + __file__ 1.13 +except NameError: 1.14 + raise AssertionError( 1.15 + "You must run this like execfile('path/to/activate_this.py', dict(__file__='path/to/activate_this.py'))") 1.16 +import sys 1.17 +import os 1.18 + 1.19 +old_os_path = os.environ['PATH'] 1.20 +os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + os.pathsep + old_os_path 1.21 +base = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 1.22 +if sys.platform == 'win32': 1.23 + site_packages = os.path.join(base, 'Lib', 'site-packages') 1.24 +else: 1.25 + site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages') 1.26 +prev_sys_path = list(sys.path) 1.27 +import site 1.28 +site.addsitedir(site_packages) 1.29 +sys.real_prefix = sys.prefix 1.30 +sys.prefix = base 1.31 +# Move the added items to the front of the path: 1.32 +new_sys_path = [] 1.33 +for item in list(sys.path): 1.34 + if item not in prev_sys_path: 1.35 + new_sys_path.append(item) 1.36 + sys.path.remove(item) 1.37 +sys.path[:0] = new_sys_path