3
|
1 |
"""By using execfile(this_file, dict(__file__=this_file)) you will
|
|
2 |
activate this virtualenv environment.
|
|
3 |
|
|
4 |
This can be used when you must use an existing Python interpreter, not
|
|
5 |
the virtualenv bin/python
|
|
6 |
"""
|
|
7 |
|
|
8 |
try:
|
|
9 |
__file__
|
|
10 |
except NameError:
|
|
11 |
raise AssertionError(
|
|
12 |
"You must run this like execfile('path/to/active_this.py', dict(__file__='path/to/activate_this.py'))")
|
|
13 |
import sys
|
|
14 |
import os
|
|
15 |
|
|
16 |
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
17 |
site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
|
|
18 |
prev_sys_path = list(sys.path)
|
|
19 |
import site
|
|
20 |
site.addsitedir(site_packages)
|
|
21 |
sys.real_prefix = sys.prefix
|
|
22 |
sys.prefix = base
|
|
23 |
# Move the added items to the front of the path:
|
|
24 |
new_sys_path = []
|
|
25 |
for item in list(sys.path):
|
|
26 |
if item not in prev_sys_path:
|
|
27 |
new_sys_path.append(item)
|
|
28 |
sys.path.remove(item)
|
|
29 |
sys.path[:0] = new_sys_path
|