1

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.

Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
Vlad the Impala
  • 15,572
  • 16
  • 81
  • 124
  • Check out this StackOverflow question: http://stackoverflow.com/questions/446052/python-best-way-to-check-for-python-version-in-program-that-uses-new-language-fe – John T Dec 14 '09 at 19:04
  • @John: I don't want the script to fail just because a user has a more recent version of Python...that seems like punishing them for good work. – Vlad the Impala Dec 14 '09 at 19:38
  • I think you would have more luck asking this on StackOverflow. – ire_and_curses Dec 14 '09 at 23:49

3 Answers3

1

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
  • 83,389
  • 16
  • 128
  • 151
  • That's exactly my problem actually...python2.5 doesn't work. Python 2.3 does. – Vlad the Impala Dec 15 '09 at 14:33
  • 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 Dec 15 '09 at 16:25
  • 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 Dec 15 '09 at 16:28
  • That might be it, because I did use MacPorts. – Vlad the Impala Dec 15 '09 at 20:34
  • 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 Dec 15 '09 at 20:40
0

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,539
  • 18
  • 26
0

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
  • 370,779
  • 53
  • 539
  • 685
  • 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 Dec 15 '09 at 20:44
  • 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 Dec 16 '09 at 01:20