![](/img/trans.png)
[英]SublimeREPL on Sublime Text 3 not importing Python 2.7 modules
[英]Sublime Text 2 and interactive Macports Python 2.7 session
我一直在尝试从sublime文本2中交互式地运行python。
我尝试了此线程中的建议: 从Sublime Text 2中交互式运行Python
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('repl_open',{"type": "subprocess",
"encoding": "utf8",
"cmd": ["python2.7", "-i", "-u", "$file"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python2.7"
})
self.window.run_command('move_to_group', { "group": 1 })
并使用键绑定:
{"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
映射到Apple的OSX本机Python安装,而不是Macports。
尝试将其更改为:
"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"
})
同
self.window.run_command('run_existing_window_command', {
"id": "repl_python",
"file": "config/Python/Main.sublime-menu"
})
我从文件/SublimeREPL/config/Python/Default.sublime-commands
借用了命令。 我个人使用IPython,因此使用选项"id" : "repl_python_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 })
看看是否可行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.