升华文本2和交互式Macports Python 2.7会话

升华文本2和交互式Macports Python 2.7会话,python,macos,sublimetext2,sublimerepl,Python,Macos,Sublimetext2,Sublimerepl,我一直在尝试从sublime text 2中以交互方式运行python 我尝试过这篇文章中的建议: 并使用密钥绑定: {"keys": ["f5"], "command": "pydev"} 然而,这是可行的,但会给我带来错误,因为我无法访问python模块 这是我正在运行的构建,工作正常,但是在我使用交互模式之前,它总是退出 { "cmd": ["python", "-ui", "$file"], "path": "/opt/local/bin:/opt/local/sbin

我一直在尝试从sublime text 2中以交互方式运行python

我尝试过这篇文章中的建议:

并使用密钥绑定:

{"keys": ["f5"], "command": "pydev"}
然而,这是可行的,但会给我带来错误,因为我无法访问python模块

这是我正在运行的构建,工作正常,但是在我使用交互模式之前,它总是退出

{
    "cmd": ["python", "-ui", "$file"],
    "path": "/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin",
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}
提前感谢您阅读本文

最有可能的python2.7映射到苹果的OSX本机Python安装,而不是Macports one

尝试将其更改为:

    "cmd": ["/opt/local/bin/python2.7", "-ui", "$file"],
尝试以下方法

替换

self.window.run_command('repl_open',{"type": "subprocess",
                                    "encoding": "utf8",
                                    "cmd": ["python2.7", "-i", "-u", "$file"],
                                    "cwd": "$file_path",
                                    "syntax": "Packages/Python/Python.tmLanguage",
                                    "external_id": "python2.7"
                               })

我从文件/subgramerepl/config/Python/Default.subgrame-commands中借用了这些命令。我个人使用IPython,所以我使用选项id:repl\u python\u IPython

无论如何,最终的插件应该是这样的

import sublime, sublime_plugin

class PydevCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.window.run_command('set_layout', {
                                 "cols":[0.0, 1.0], 
                                 "rows":[0.0, 0.5, 1.0], 
                                 "cells":[[0, 0, 1, 1], [0, 1, 1, 2]]
                              })
        self.window.run_command('run_existing_window_command', {
                        "id": "repl_python",
                        "file": "config/Python/Main.sublime-menu"
                    })
        self.window.run_command('move_to_group', { "group": 1 })
看看这是否有效

self.window.run_command('run_existing_window_command', {
                        "id": "repl_python",
                        "file": "config/Python/Main.sublime-menu"
                    })
import sublime, sublime_plugin

class PydevCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.window.run_command('set_layout', {
                                 "cols":[0.0, 1.0], 
                                 "rows":[0.0, 0.5, 1.0], 
                                 "cells":[[0, 0, 1, 1], [0, 1, 1, 2]]
                              })
        self.window.run_command('run_existing_window_command', {
                        "id": "repl_python",
                        "file": "config/Python/Main.sublime-menu"
                    })
        self.window.run_command('move_to_group', { "group": 1 })