如何永久添加Python导入路径? [英] How do I add a Python import path permanently?
本文介绍了如何永久添加Python导入路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以像这样添加Python的导入路径:
I know that I can add an import path to Python like this:
import sys
sys.path.append("/path/to/directory/")
但是,当我重启Python,这已经一去不复返了。如果我不得不一直这样做,我会觉得很烦人,我想一劳永逸地做到这一点并完成它。
But, when I restart Python, this is gone. I'd find it quite annoying if I had to do this all the time, I'd like to do this once and for all and be done with it.
所以, 怎么样?我在哪里可以找到该文件?或者我需要编辑其他内容吗?我正在使用最新版本的Ubuntu。
So, how? Where can I find that file? Or do I need to edit something else? I'm using the latest version of Ubuntu.
推荐答案
来自 man python
~/.pythonrc.py
User-specific initialization file loaded by the user module; not used by default or by most applications.
ENVIRONMENT VARIABLES
PYTHONPATH
Augments the default search path for module files. The format is the same as the shell's $PATH: one or more directory pathnames
separated by colons. Non-existent directories are silently ignored. The default search path is installation dependent, but gen-
erally begins with ${prefix}/lib/python<version> (see PYTHONHOME above). The default search path is always appended to $PYTHON-
PATH. If a script argument is given, the directory containing the script is inserted in the path in front of $PYTHONPATH. The
search path can be manipulated from within a Python program as the variable sys.path .
这篇关于如何永久添加Python导入路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文