问题
I am building a Python script for processing json data according to some criteria. Also I have built a custom module which consists of methods for retrieving json data and generation of json file which consist of processed data. But that module file is stored into S3 bucket and I need to import that module into my script so that I can invoke functions defined in module.
Please suggest me appropriate solution regarding importing python module from external URL
回答1:
Well, you could download the file using urllib2 and then import it, if the online module is all in one file:
from urllib2 import urlopen
r = urlopen('http://urlHere/fileHere')
f = open('filenameToWrite', 'w')
f.write(r.read())
f.close()
import filenameWithout.PyInIt
回答2:
Package your module into your favorite extension (tarball, wheel, etc.) using setuptools and then you will be able to install it using pip as bruno by doing something like:
pip install --no-index --trusted-host s3_ip/host --find-links http://s3.com...
回答3:
Please see my answer to question # 48905127 - believed to be the best solution I found so far and comes with detailed steps and code snippets ready for you to copy and use.
来源:https://stackoverflow.com/questions/32352187/import-python-module-from-external-url