import sys sys.setdefaultencoding('utf-8') sys.path.append("你想導入的包的路徑") #接下來即可引用其他目錄下的模塊 from [包].[包].[.py文件] import [方法]
一個python包中必須有__init__.py 文件才能被識別為python包。切__init__.py中必須聲明同級目錄下所有.py文件中 [....].py 的方括號部分,否則from ... import * 時會出現部分模塊導入不了的問題。
#__init__.py文件 __all__ = ["hello",]