PYTHONSTARTUP not working on debian?

David M. Cooke cookedm+news at physics.mcmaster.ca
Thu May 24 02:00:58 EDT 2001


At some point, Bruce Sass <bsass at freenet.edmonton.ab.ca> wrote:

> On Wed, 23 May 2001, Rainy wrote:
> 
> > I'm running debian unstable, python 1.5, 2.0 and 2.1(compiled),
> > and PYTHONSTARTUP is set to ~/.pythonrc.py, which contains
> > line import time. When I start interactive session, and try
> > time.time() for example, it gives me a name error, as if
> > time isn't imported. What's wrong?
> 
> Same setup here, ~/.pythonrc.py looks like this:
> 
> ---
> print "importing os, sys..."
> import os, sys
> 
> if sys.version[:3] == '2.1':
>     print "importing pydoc.help..."
>     from pydoc import help
> ---
> 
> It works OK from a text console, or when starting from the commandline
> of a Konsole session... but not when started from Konsole's File menu.
> So, there is something in how python gets started that affects if
> .pythonrc.py is read (guessing, the difference between starting from a
> shell commandline and doing "exec python").
> 

Probably because when it's run from the file menu, the environment isn't set
up as you expect it. Here's a short program to test what environment
it's sending:

---8<---
#!/usr/bin/env python
import Tkinter, os

if __name__ == '__main__':
    root = Tkinter.Tk()
    for e, v in os.environ.items():
        Tkinter.Label(root, text='%s=%s'%(e,v)).pack()
    root.mainloop()
--->8----

In general, if you set some environment variables in your .bashrc or
.tcshrc, etc., those won't be set if that file isn't run (which it
usually isn't when starting a X session!)

If you use a .xsession file to start up your window manager, I suppose
you could set PYTHONSTARTUP, etc. there, and it should be set globally
in your X session.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list