How to import python module accessible via url

My company uses some kind of version control archiving tool (Microsoft Windows), and I would like to import directly from it. But I canโ€™t find a way to do this.

Here is what I tried:

>>> import sys
>>> sys.path.append(r"http://some_path_copied_and_pasted/05.Autres%20Outils/Regen_Engine")
>>> sys.path
['C:\\Python26\\Lib\\idlelib', 'C:\\Python26\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\site-packages', 'http://some_path_copied_and_pasted/05.Autres%20Outils/Regen_Engine']
>>> import regen_engine as r
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    import regen_engine as r
ImportError: No module named regen_engine

I tried replacing the "% 20" URL with "" (spaces), but the result is the same. I also tried using a module imp, but not better.

So here are my questions:

  • Can I import from a URL?
  • if so, how can i do this?

Perhaps the solution could be to access this file using another hidden Sharepoint path, so a tag would be appropriate for it.

+5
source share
2 answers
import urllib
def urlimport(x):
    exec urllib.urlopen(x) in globals()

, , .

+2

Try:

def dynamic_import_by_uri(file)
    file = os.path.abspath(file)
    exec open(file, 'rb') in globals()

, ...

+1

All Articles