Adding folder to Python's path permanently

后端 未结 4 570
北海茫月
北海茫月 2020-12-02 21:57

I\'ve written a library in python and I want it to reside in a common location on the file system.

From my script, I just want to do:

>>> im         


        
4条回答
  •  情书的邮戳
    2020-12-02 22:24

    Another possibility is to alter the sys.path in your sitecustomize.py, a script that is loaded as Python startup time. (It can be put anywhere on your existing path, and can do any setup tasks you like; I use it to set up tab completion with readline too.)

    The site module offers a method that takes care of adding to sys.path without duplicates and with .pth files:

    import site
    site.addsitedir(r'C:\MyFolder\MySubFolder')
    

提交回复
热议问题