Uploading Python third party libraries

后端 未结 2 1318
长情又很酷
长情又很酷 2020-12-09 13:57

Google App engine documentation states that it is possible to upload and use third party libraries provided they written in pure Python.

What are the steps I need to

2条回答
  •  一个人的身影
    2020-12-09 14:15

    Well I tried the same with following steps.

    1. created a directory(lib) with init file i.e lib/__init__.py in my project root.
    2. created my module (mymodule.py), and defined a function i.e.

      def myfunc():
          return "mycustomfunction"
      
    3. imported mymodule in my main.py

      from lib import mymodule
      

    I could use the returned value from myfunc() and could pass that as a template value to my jinja2 template

    Similarly, if we follow what @rjz also pointed out in the first answer, if the 3rd Party library is just a module then we can keep that in libs with an init file and it can be imported with an import statement ( point 3) . If the 3rd party library is a package then we can keep it in the project root and import it again with an import statement as this one in the main.py:

    from thirdpartypackage import * 
    

提交回复
热议问题