Stormbytes
Stormbytes

Reputation: 177

How do I use Python 3.1.2 in Textmate?

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!

Upvotes: 1

Views: 3088

Answers (2)

Michael
Michael

Reputation: 11

#! /usr/bin/python

Take away this normal she bang from your script then run it you will then have version 3 show up in textmates window. The default shebang overrides the variable and sends you back to osx default version 2.6.1. It is all a bit weird....

Upvotes: 1

Ned Deily
Ned Deily

Reputation: 85095

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.

Upvotes: 1

Related Questions