Import Script from a Parent Directory

后端 未结 3 1206
天命终不由人
天命终不由人 2020-11-29 01:20

How do I import a module(python file) that resides in the parent directory?

Both directories have a __init__.py file in them but I still cannot import a

3条回答
  •  长情又很酷
    2020-11-29 01:36

    If you want to run the script directly, you can:

    1. Add the FolderA's path to the environment variable (PYTHONPATH).
    2. Add the path to sys.path in the your script.

    Then:

    import module_you_wanted
    

提交回复
热议问题