Permanently add a directory to PYTHONPATH?

前端 未结 19 1304
别那么骄傲
别那么骄傲 2020-11-22 01:12

Whenever I use sys.path.append, the new directory will be added. However, once I close python, the list will revert to the previous (default?) values. How do I

19条回答
  •  被撕碎了的回忆
    2020-11-22 01:46

    You could add the path via your pythonrc file, which defaults to ~/.pythonrc on linux. ie.

    import sys
    sys.path.append('/path/to/dir')
    

    You could also set the PYTHONPATH environment variable, in a global rc file, such ~/.profile on mac or linux, or via Control Panel -> System -> Advanced tab -> Environment Variables on windows.

提交回复
热议问题