__init__.py 659 B

1234567891011121314151617181920212223
  1. def _fixup_dlls():
  2. try:
  3. path = __path__[0]
  4. except (NameError, IndexError):
  5. return # Not a package, or not on filesystem
  6. import os
  7. relpath = os.path.relpath(path, __path__[-1])
  8. dll_path = os.path.abspath(os.path.join(__path__[-1], '../bin', relpath))
  9. if not os.path.isdir(dll_path):
  10. return
  11. if hasattr(os, 'add_dll_directory'):
  12. os.add_dll_directory(dll_path)
  13. else:
  14. os_path = os.environ.get('PATH', '')
  15. os_path = os_path.split(os.pathsep) if os_path else []
  16. os_path.insert(0, dll_path)
  17. os.environ['PATH'] = os.pathsep.join(os_path)
  18. _fixup_dlls()
  19. del _fixup_dlls