In Python script, how do I set PYTHONPATH?

前端 未结 6 1888
一个人的身影
一个人的身影 2020-11-28 05:45

I know how to set it in my /etc/profile and in my environment variables.

But what if I want to set it during a script? Is it import os, sys? How do I do it?

6条回答
  •  死守一世寂寞
    2020-11-28 06:27

    you can set PYTHONPATH, by os.environ['PATHPYTHON']=/some/path, then you need to call os.system('python') to restart the python shell to make the newly added path effective.

提交回复
热议问题