Import python package from local directory into interpreter

前端 未结 9 1859
野的像风
野的像风 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

    If you want to run an unmodified python script so it imports libraries from a specific local directory you can set the PYTHONPATH environment variable - e.g. in bash:

    export PYTHONPATH=/home/user/my_libs
    python myscript.py
    

    If you just want it to import from the current working directory use the . notation:

    export PYTHONPATH=.
    python myscript.py
    

提交回复
热议问题