问题描述
如何安装pythonstartup
文件,使其在python myfile.py
之类的命令上运行?
How do I install the pythonstartup
file so that it runs on command like python myfile.py
?
我试图将其安装到Ubuntu的/home/myuser
目录中,但是它说我没有足够的权限.此外,不同的地方交替表示应该大写或小写,并在其前加句号. Python命令行指南似乎并未解释将文件放置在何处,或如何更改要指向"该文件的环境变量.
I tried to install it into my /home/myuser
directory for Ubuntu, but it said that I had insufficient permissions. Furthermore, different places say alternately that it should be in all caps or in all lower case with a period before it. The Python command line guide does not seem to explain where to put the file, or how to change which environment variable to 'point' to it.
推荐答案
在您的~/.bashrc
中:
export PYTHONSTARTUP=$HOME/.pythonstartup
并将python代码放在$HOME/.pythonstartup
中,例如:
and put your python code in $HOME/.pythonstartup
, like:
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")
然后运行交互式外壳:
python
查看从PYTHONSTARTUP导入的内容.这仅适用于python交互模式.
See the imports from PYTHONSTARTUP are processed. This only works in python interactive mode.
有关PYTHONSTARTUP
变量的更多信息,请阅读python手册页:
For more information about PYTHONSTARTUP
variable, read the python man page:
$ man python
这篇关于安装pythonstartup文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!