how to import a 'zip' file to my .py

后端 未结 2 1801
暗喜
暗喜 2020-12-18 03:48

when i use http://github.com/joshthecoder/tweepy-examples ,

i find :

import tweepy

in the appengine\\oauth_example\\handlers.py

相关标签:
2条回答
  • 2020-12-18 03:53

    The name of the zip file is irrelevent when searching for modules - this allows you to include version numbers in the file name, such as my_b_package.1.2.3.zip.

    To import from a zip file, you need to replicate the full package structure within it. In this case, you need a package b, with the __init__.py and c.py modules.

    I.e:

    b.zip
    |
    | -- b <dir>
         | -- __init__.py
         | -- c.py
    
    0 讨论(0)
  • 2020-12-18 03:58

    You don't import zip files, you add them to sys.path so that you can import modules within them. sys.path is a list, and as such the normal list methods/operations (e.g. .append()) all work on it.

    0 讨论(0)
提交回复
热议问题