views:

126

answers:

3

I had Python v2.3 on my system. When I wanted to run a Tkinter script I could just use

python myscript.py

I recently upgraded to Python 2.5 and now I need to have X11 running and the "DISPLAY" environment variable set before I can run any of my scripts. This is bad for me, because I can't distribute any scripts without explicitly stating "if you're running Python > v2.3, you will need to have X11 open before running this script". Is there a way around this? I'm on OS X Tiger.

A: 

I have installed Python 2.6.4 and I haven't any problem at all running it without a $DISPLAY variable ...

I'm on linux ...

Edo
+1  A: 

Install python2.5 or python2.6 for OS X from python.org. They use the native Aqua Tk and thus do not require X11 for IDLE or python scripts that use Tkinter.

Ned Deily
That's exactly my problem actually...python2.5 doesn't work. Python 2.3 does.
Goose Bumper
If you installed a python.org python, by default it resides at /usr/local/bin/python (actually symlinks to /Library/Frameworks/Python.framework/Versions/2.n/bin) rather than /usr/bin/python, so make sure your shell $PATH reflects that. What Python modules do the scripts use? As far as I know, there is nothing in the Python standard library supplied with those installers that uses X11.
Ned Deily
BTW, if you installed a python2.5 from Fink or possibly MacPorts, they may be built with a Tk that uses X11. Use the python.org version instead or ensure that their Aqua Tk variants are used.
Ned Deily
That might be it, because I did use MacPorts.
Goose Bumper
That's certainly it and that's why I specifically mentioned using python.org pythons. You *may* be able to get the MacPorts Tk and python2.5 all working on 10.4 with $ sudo port tk +quartz ; you may need to reinstall python to get tkinter rebuilt. You may just be better off, in this case, using the python.org one and, possibly, installing a newer Tcl/Tk 8.4 from ActiveState.
Ned Deily
A: 

If I had to guess (and I do...), it sounds like you installed an X11 based version of python and tkinter rather than one that uses the native windowing system on OSX. I think you can safely write your scripts without telling people they have to have X11 running. You merely have to say they have to have a proper environment set up -- either a native version of python+Tkinter or have X11 running and have an X11-based version of python+Tkinter

In other words, this isn't a regression in python that you have to code around, it's just a side effect of your particular installation of python.

Bryan Oakley
But there's no reason to live with this. Just install the proper version of python as I explained. Having to now run with X11 Tk vs the previous native Tk is very user unfriendly and totally unnecessary.
Ned Deily
Oh, agreed! No reason to live with it. My point was to reassure Goose Bumper that it wasn't a regression in Python, just an artifact of what he chose to install.
Bryan Oakley