Sublime Text下配置Python3开发环境

3 篇文章 0 订阅
3 篇文章 0 订阅

原来用的是Eclipse+PyDev写一些Python的小脚本,用上Sublime之后,就尝试在Sublime下面写python代码,发现Sublime的编译运行功能只是看起来很美,实际上连输入的功能都没有,于是安装了插件SublimeREPL,ctrl + shift + p 显示命令输入栏,输入SublimeREPL:Python RUN就能运行当前文件,而不输入Run就是进入Python 的命令行。经常用之后只要输入run就可以很方便地运行了,唯一的缺点是不能显示运行中的异常信息。另外,我还安装了All Autocomplete,Jedi 等等一堆Python语法自动补全插件 ,写代码从未如此简单!不过之后我悲伤地发现,SublimeREPL下面运行的是Python2.7.5,而我同时装了Python2.7.5和Python3.3.0,于是我就手动地添加了一个配置文件夹,让SublimeREPL能够运行Python3,文件夹新建在如下目录下

sublime安装位置\Data\Packages\SublimeREPL\config\
文件夹中包含 Default.sublime-commands 和 Main.sublime-menu 两个文件

Default.sublime-commands 内容如下

[
    {
        "caption": "SublimeREPL: Python3",
        "command": "run_existing_window_command", "args":
        {
            "id": "repl_python",
            "file": "config/Python/Main.sublime-menu"
        }
    },
    {
        "caption": "SublimeREPL: Python3 - RUN current file",
        "command": "run_existing_window_command", "args":
        {
            "id": "repl_python_run",
            "file": "config/Python3/Main.sublime-menu"
        }
    }
]

Main.sublime-menu文件内容如下

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

                 "children":[
                    {"command": "repl_open",
                     "caption": "Python3",
                     "id": "repl_python",
                     "mnemonic": "p",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python3", "-i", "-u"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python3",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    // {"command": "python_virtualenv_repl",
                    //  "id": "python_virtualenv_repl",
                    //  "caption": "Python - virtualenv"},
                    // {"command": "repl_open",
                    //  "caption": "Python - PDB current file",
                    //  "id": "repl_python_pdb",
                    //  "mnemonic": "d",
                    //  "args": {
                    //     "type": "subprocess",
                    //     "encoding": "utf8",
                    //     "cmd": ["python", "-i", "-u", "-m", "pdb", "$file_basename"],
                    //     "cwd": "$file_path",
                    //     "syntax": "Packages/Python/Python.tmLanguage",
                    //     "external_id": "python",
                    //     "extend_env": {"PYTHONIOENCODING": "utf-8"}
                    //     }
                    // },
                    {"command": "repl_open",
                     "caption": "Python3 - RUN current file",
                     "id": "repl_python_run",
                     "mnemonic": "d",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python3", "-u", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    }
                ]}
            ]
        }]
    }
]
保存之后运行Sublime Text 就能在Tools-->SublimeREPL下看到Python3的条目。 注意:要确认你可以从命令行中输入命令“Python3”可以运行Python3

试试看,运行Python3,,成功!


评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值