本文介绍了如何在 sublime text 3 中访问 python shell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为全栈python开发设置sublime text.我的意思是:1. python shell,我可以在其中输入表达式并立即获得结果,2. shell 会为'input' 方法工作,它会提示用户输入数据.

Is it possible to set up sublime text for full stack python development. By this, I mean the following: 1. python shell where I can input an expression and instantly get the result, 2. the shell will work for the 'input' method, which will prompt the user to enter data.

我已经安装了主题和配色方案,但是控制台/shell 不工作或者我没有从包控件中获得正确的包.我想要一个可以在 sublime text 中工作而无需进入 IDLE 的环境.如果你知道怎么做,请帮助我.

I have installed the theme and color scheme, but the console/shell is not working or I did not get the correct package from the package control. I want an environment where I can work in the sublime text without shifting into the IDLE. Please help me kindly if you know how to do it.

推荐答案

有几种方法可以做到这一点:

There are several ways to do this:

正如@cricket_007 所述,您可以安装 SublimeREPL 并通过 Tools >>> 运行当前文件.SublimeREPL >>>Python >>>Python - 运行当前文件.这会在 Sublime Text 视图中解释 python 文件,并且可以输入.但是,由于这不是构建系统,因此您可以从中创建构建系统(单击 Tools >>> Build System >>> New Build System... 并粘贴):

As @cricket_007 states you can install SublimeREPL and run the current file via Tools >>> SublimeREPL >>> Python >>> Python - Run current file. This interprets the python file in a Sublime Text view and inputs are possible. However since this is not a build system you can create a build system from this (click Tools >>> Build System >>> New Build System... and paste):

{
    "target": "repl_open",
    "encoding": "utf8",
    "syntax": "Packages/Python/Python.tmLanguage",
    "extend_env": {"PYTHONIOENCODING": "utf-8"},
    "type": "subprocess",
    "cmd": ["python", "-u", "$file"],
    "cwd": "$file_path",
    "external_id": "python",
    "selector": "source.python"
}

作为替代方案,可以使用以下构建系统在终端中运行该文件.这将创建一个新终端并在 python 中执行该文件,然后等待按 Enter.

As an alternative one could run the file in a terminal, by using the following build system. This will create a new terminal and execute the file in python and afterwards await pressing enter.

{
    "selector": "source.python",
    "windows": {
        "shell_cmd": "start \"$file_name\" cmd /c \"python $file_name & pause\""
    },
    "linux": {
        "shell_cmd": "xterm -T \"$file_name\" -e bash -c \"python $file_name; echo Press enter to exit... & read\""
    }
}

随意添加 osx 选项

这篇关于如何在 sublime text 3 中访问 python shell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 17:45