How to import custom python package by name

前端 未结 2 2169
醉酒成梦
醉酒成梦 2021-01-07 05:09

I have created a folder named \"custom_module\" and I have the __init__.py inside the folder which contains:

__all__ = [
        \'Submodule1\',
        \'Su         


        
2条回答
  •  渐次进展
    2021-01-07 05:27

    sys.path holds the Python search path. Before trying to import your modules and packages, set it to include your path:

    import sys
    sys.path.insert(0, 'your_path_here')
    import custom_module
    

    More detail in the Python docs and in this question

提交回复
热议问题