How to refresh sys.path?

前端 未结 2 1096
夕颜
夕颜 2020-12-16 16:22

I\'ve installed some packages during the execution of my script as a user. Those packages were the first user packages, so python didn\'t add ~/.local/lib/python2.7/si

2条回答
  •  没有蜡笔的小新
    2020-12-16 16:37

    As explained in What sets up sys.path with Python, and when? sys.path is populated with the help of builtin site.py module.

    So you just need to reload it. You cannot it in one step because you don't have site in your namespace. To sum up:

    import site
    from importlib import reload
    reload(site)
    

    That's it.

提交回复
热议问题