Reputation: 66560
I have this code:
<script type="text/python" src="https://cdn.jcubic.pl/StringIO.py"></script>
<script type="text/python">
f = StringIO()
</script>
(StringIO came from https://svn.python.org/projects/python/trunk/Lib/StringIO.py with removed __main__
because it get executed)
and got error:
Traceback (most recent call last):
NameError: name 'StringIO' is not defined
How can I import python library from URL? Is there a way?
UPDATE found it that in Python 3 and Brython StringIO
is in io
module but still I would like to know how to import module from url if it's possible.
Upvotes: 2
Views: 782
Reputation: 111
You need to place it into server side brython/Lib/site-packages directory. It needs to be pure python naturally.
Also note, that you should be able to modify the sys.path search direcotries in with pythonpath setting:
<body onload="brython(
debug:1,
pythonpath:['http://example.com/brython/Lib/', 'http://e... ]
)"
>
So note that the paths are actually full URLs to module paths. It took some time to me figure it out as documentation (currently now at 2018-03-20 brython-3.4.0) does not give an example of that.
Also note that touching pythonpath value overwrites the defaults and you need to include them as well. In my understanding those are the current Apache PATH_INFO environment value, that is the current loaded path and the brython source tree Lib/site-packages.
Upvotes: 2