如何在 Textmate 中使用 Python 3.1.2?

发布于 2024-09-16 12:22:26 字数 228 浏览 8 评论 0原文

TextMate 1.5.9似乎使用Python 2.6.1。如何将其配置为使用 3.1?我已经安装了 3.1 软件包,并且可以使用 IDLE 进行交互式会话,但我现在想使用 TextMate。我已经看过指导您定义项目变量(TM_PYTHON:解释器路径)的帖子。我尝试了这个,但是当我使用 Cmd+r 在 Textmate 中运行脚本时,我仍然看到 Python 2.6.1 作为版本号(上/右)。连终端都用2.7!

帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ˉ厌 2024-09-23 12:22:26

我假设您指的是这篇文章。它应该可以工作,但请确保您使用安装的 Python 3.1 的正确路径。检查:

$ which python3
/usr/local/bin/python3

如果您使用了 python.org 3.1 安装程序,它应该可以在 /usr/local/bin/python3 中找到。其他方法可能会有所不同,例如,MacPorts python3.1 通常位于 /opt/local/bin/python3

更新:既然您指出它仍然对您不起作用,我的猜测是我们正在使用不同版本的 TextMate 的 Python 包。使用 TextMate Bundle Editor(菜单项 Bundles -> Bundle Editor -> Show Bundle Editor),然后选择 Python 包的 Run Script 命令,我看到以下命令片段:

#!/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 = "&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

看看有没有一样的。如果没有,您应该考虑更新 TextMate 和/或捆绑包。 GetBundle 捆绑包可以轻松地使捆绑包保持最新,如此处

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 = "&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.

情深缘浅 2024-09-23 12:22:26
#! /usr/bin/python

从你的脚本中去掉这个正常的 she bang 然后运行它,你就会在 textmates 窗口中显示版本 3。默认的 shebang 会覆盖该变量并将您带回 osx 默认版本 2.6.1。一切都有点奇怪......

#! /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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文