Guest User

Untitled

a guest
Oct 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. # just test for a single pyd file that I removed from a non-zipped folder
  2. class CustomImporter(object):
  3.  
  4. virtual_name = 'pandas._libs.tslib' # a pyd file
  5.  
  6. def find_module(self, fullname, path=None):
  7.  
  8. if fullname == self.virtual_name:
  9. return self
  10.  
  11. return None
  12.  
  13. def load_module(self, fullname):
  14.  
  15. if fullname in sys.modules:
  16. return sys.modules[fullname]
  17.  
  18. if fullname != self.virtual_name:
  19. raise ImportError(fullname)
  20. try:
  21. path = r"C:.....tslib.cp35-win_amd64.pyd"
  22. module = imp.load_dynamic("tslib",path )
  23. module.__file__ = path
  24. module.__loader__ = self
  25. module.__name__ = self.virtual_name
  26. sys.modules[self.virtual_name] = module
  27. except BaseException as e:
  28. raise ImportError(fullname + str(e))
  29.  
  30. return module
  31.  
  32. sys.meta_path.append(CustomImporter())
Add Comment
Please, Sign In to add comment