安装pythonstartup文件 [英] Installing pythonstartup file

查看:197
本文介绍了安装pythonstartup文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何安装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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆