2

我最近在我的电脑(Ubuntu 13.10)中安装了 sublime text 3。而且我还安装了 Canopy Enthought 并将 canopy 设置为默认 python。但是 Sublime text 没有使用新的默认 python 和 ipython,而是使用“旧”版本。在 Windows 中,我曾经使用 SublimeREPL 运行 ipython 控制台,而 Canopy 没有问题。我在终端验证了以下结果:

    ~$ which python
    /home/ccp/Enthought/Canopy_64bit/User/bin/python
    ~$ which ipython
    /home/ccp/Enthought/Canopy_64bit/User/bin/ipython

所以默认情况下使用 Canopy 没有问题,在终端中我可以访问 Canopy python 2.7.3 以及带有 python 2.7.3 的 ipython 但在 sublimeREPL 中打开 python2.7.5+(Ubuntu“旧”默认)。有什么地方可以改吗?我尝试重新安装 Sublime Text 3,但没有解决问题。

终端:

    Enthought Canopy Python 2.7.3 | 64-bit | (default, Dec  2 2013, 16:23:35) 
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 

蟒蛇(SUBLIMEREPL):

    Python 2.7.5+ (default, Sep 19 2013, 13:48:49) 
    [GCC 4.8.1] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
4

2 回答 2

2

创建一个包含以下内容的新文件:

[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "r",
            "id": "SublimeREPL",
            "children":
            [
                {"caption": "Python",
                "id": "Python",

                 "children":[
                    {"command": "repl_open",
                     "caption": "Python - Canopy",
                     "id": "repl_python",
                     "mnemonic": "p",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["/home/ccp/Enthought/Canopy_64bit/User/bin/python", "-i", "-u"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - IPython - Canopy",
                     "id": "repl_python_ipython",
                     "mnemonic": "p",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "autocomplete_server": true,
                        "cmd": ["/home/ccp/Enthought/Canopy_64bit/User/bin/python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {
                            "PYTHONIOENCODING": "utf-8",
                            "SUBLIMEREPL_EDITOR": "$editor"
                        }
                    }
                    }
                ]}
            ]
        }]
    }
]

并将其另存为~/.config/sublime-text-3/Packages/User/SublimeREPL/config/Python/Main.sublime-menu. 这将在菜单中添加Python - CanopyPython - IPython - Canopy选项Tools -> SublimeREPL -> Python

于 2014-01-08T15:12:31.083 回答
1

谢谢,实际上解决了这个问题!现在我也可以用 ctrl+shift+i 打开 ipython-Canopy。如果有人想要这种配置,我的键绑定-用户如下:

[{ "keys": ["ctrl+shift+i"],                    
                     "command": "repl_open",
                     "caption": "Python - IPython - Canopy",
                     "id": "repl_python_ipython",
                     "mnemonic": "p",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "autocomplete_server": true,
                        "cmd": ["/home/ccp/Enthought/Canopy_64bit/User/bin/python", "-u",         "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {
                            "PYTHONIOENCODING": "utf-8",
                            "SUBLIMEREPL_EDITOR": "$editor"
                        }
                    }},
{ "keys": ["ctrl+7"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+7"], "command": "toggle_comment", "args": { "block": true } },
]
于 2014-01-08T16:32:16.053 回答