You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.1 KiB

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