Import python package from local directory into interpreter

前端 未结 9 1858
野的像风
野的像风 2020-11-29 02:54

I\'m developing/testing a package in my local directory. I want to import it in the interpreter (v2.5), but sys.path does not include the current directory. Right now I type

9条回答
  •  醉话见心
    2020-11-29 03:40

    I used pathlib to add my module directory to my system path as I wanted to avoid installing the module as a package and @maninthecomputer response didn't work for me

    import sys
    from pathlib import Path
    
    cwd = str(Path(__file__).parent)
    sys.path.insert(0, cwd)
    from my_module import my_function
    

提交回复
热议问题