views:

101

answers:

2

TextMate 1.5.9 seems to use Python 2.6.1. How do you configure it to use 3.1 instead? I've already installed the 3.1 package and I can use IDLE for interactive sessions, but I want to use TextMate now. I've already seen the post that directs you to define a project variable (TM_PYTHON : interpreter path). I tried this, but when i use Cmd+r to run a script in Textmate I still see Python 2.6.1 as the version number (top/right). Even the Terminal uses 2.7!

Help!

A: 

I assume you are referring to this post. It should work but make sure you are using the right path to the Python 3.1 you installed. Check with:

$ which python3
/usr/local/bin/python3

If you used the python.org 3.1 installer, it should be available at /usr/local/bin/python3. Other methods may vary, for instance, the MacPorts python3.1 would normally be at /opt/local/bin/python3.

UPDATE: Since you indicate that it still doesn't work for you, my guess is that we are using different versions of TextMate's Python bundle. Using the TextMate Bundle Editor (menu item Bundles -> Bundle Editor -> Show Bundle Editor) then selecting the Python bundle's Run Script command, I see the following command snippet:

#!/usr/bin/env ruby
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"

TextMate.save_current_document
TextMate::Executor.make_project_master_current_document

ENV["PYTHONPATH"] = ENV["TM_BUNDLE_SUPPORT"] + (ENV.has_key?("PYTHONPATH") ? ":" + ENV["PYTHONPATH"] : "")

is_test_script = ENV["TM_FILEPATH"] =~ /(?:\b|_)(?:test)(?:\b|_)/ or
                 File.read(ENV["TM_FILEPATH"]) =~ /\bimport\b.+(?:unittest)/

TextMate::Executor.run(ENV["TM_PYTHON"] || "python", "-u", ENV["TM_FILEPATH"]) do |str, type|
  if is_test_script and type == :err
    if str =~ /\A[\.F]*\Z/
      str.gsub!(/(\.|F)/, "<span class=\"test ok\">\\1</span>")
      str + "<br/>\n"
    elsif str =~ /\A(FAILED.*)\Z/
      "<div class=\"test fail\">#{htmlize $1}</div>\n"
    elsif str =~ /\A(OK.*)\Z/
      "<div class=\"test ok\">#{htmlize $1}</div>\n"
    elsif str =~ /^(\s+)File "(.+)", line (\d+), in (.*)/
      indent = $1
      file   = $2
      line   = $3
      method = $4
      indent += " " if file.sub!(/^\"(.*)\"/,"\1")
      url = "&amp;url=file://" + e_url(file)
      display_name = ENV["TM_DISPLAYNAME"]
      "#{htmlize(indent)}<a class=\"near\" href=\"txmt://open?line=#{line + url}\">" +
        (method ? "method #{CGI::escapeHTML method}" : "<em>at top level</em>") +
        "</a> in <strong>#{CGI::escapeHTML display_name}</strong> at line #{line}<br/>\n"
    end
  end
end

Check and see if you have the same. If not, you should consider updating TextMate and/or the bundle. The GetBundle bundle makes it easy to keep bundles up-to-date as described here.

Ned Deily
Typing "which python3" in the terminal window yields "/usr/local/bin/python3". So as per the referenced post, I created a new project in TM, hit cmd+i on the project and added a project variable "TM_PYTHON" with a value of "/usr/local/bin/python3". When I hit cmd+r I get Textmate's python window (whatever its called) and in the top right it says "Python 2.6.1"
Stormbytes