Python:每次我重新启动解释器时,都会撤消sys.path中项目的删除 [英] Python: deletion of item in sys.path is undone each time I restart the interpreter
问题描述
>>> sys.path[6]
/path/to/django
>>> sys.path.pop(6)
/path/to/django
然后CTRL + D
$ python
>>> sys.path[6]
/path/to/django
亲爱的...
推荐答案
sys.path从外部维护的PYTHONPATH变量填充.重新启动python时,请更改此变量以进行永久更改.
sys.path is populated from the externally maintained PYTHONPATH variable. Change this variable to get a permanent change when you restart python.
在使用bash的Unix(包括Mac)上,其配置如下:
On unix (including Macs) when using bash it's configured most likely like this:
导出PYTHONPATH = ....
export PYTHONPATH=....
此语句很可能隐藏在您的.profile或.bashrc文件中.
And this statement is most likely hiding in your .profile or .bashrc file.
要在Windows中执行此操作,您需要执行类似的操作
To do this in Windows you need to do something like
SET PYTHONPATH = ....
SET PYTHONPATH=....
它可能在系统控制面板中的某个位置-在环境下.
And it's probably somewhere in the system control panel - under environment.
如果要查看PYTHONPATH的当前设置,请转到命令(终端)窗口,然后键入echo $PYTHONPATH
(unix)或echo %PYTHONPATH%
(windows)
If you want to see your current setting for PYTHONPATH, go to command (terminal) window and type echo $PYTHONPATH
(unix) or echo %PYTHONPATH%
(windows)
这篇关于Python:每次我重新启动解释器时,都会撤消sys.path中项目的删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!