1
0

sitecustomize.py 686 B

1234567891011121314151617181920212223242526
  1. """Hook for cleaning the paths detected by Python
  2. """
  3. import os
  4. import sys
  5. def clean_path():
  6. site_packages = "/usr/local/lib/python{:}.{:}/site-packages".format(
  7. *sys.version_info[:2])
  8. binaries_path = "/usr/local/bin"
  9. env_path = os.getenv("PYTHONPATH")
  10. if env_path is None:
  11. env_path = []
  12. else:
  13. env_path = [os.path.realpath(path) for path in env_path.split(":")]
  14. if ((os.path.dirname(sys.executable) != binaries_path) and
  15. (site_packages not in env_path)):
  16. # Remove the builtin site-packages from the path
  17. try:
  18. sys.path.remove(site_packages)
  19. except ValueError:
  20. pass
  21. clean_path()