安装python启动文件 [英] Installing pythonstartup file
问题描述
如何安装 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")
然后运行交互式shell:
Then run the interactive shell:
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
这篇关于安装python启动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!