Set up Python 3 build system with Sublime Text 3

后端 未结 8 2188
青春惊慌失措
青春惊慌失措 2020-11-28 21:46

I want to configure Sublime Text 3 to build Python 3, but I don\'t seem to understand how the builds work. Many tutorials have told me to make a build file containing code s

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 22:32

    Steps to Make Sublime Text a Python IDE (Windows)

    Tested successfully on Sublime Text 3. Assuming Sublime Text and package control are already installed . . .

    1. Install Python (python.org) and pay attention to where it is installed or choose a simple location like the C drive, agreeing to remove character limit at the end of the installation.

    2. Install package SublimeREPL (Cntrl + Shift + P, Package Control - Install Package, SublimeREPL, Enter).

    3. Go to Preferences, Package Settings, SublimeREPL, Settings - User.

    4. Paste in the following, updating the file path to your python installation folder, as needed. You may customize these and choose whatever syntax you like (last line) but I prefer my output in plain text.

      {
        "default_extend_env": {"PATH":"C:\\Program Files\\Python36\\"},
        "repl_view_settings": {
        "translate_tabs_to_spaces": false,
        "auto_indent": false,
        "smart_indent": false,
        "spell_check": false,
        "indent_subsequent_lines": false,
        "detect_indentation": false,
        "auto_complete": true,
        "line_numbers": false,
        "gutter": false,
        "syntax": "Packages/Text/Plain text.tmLanguage"
        }
      }
      
    5. Save and close the file (SublimeREPL.sublime-settings).

    6. Go to Tools, Build System, New Build System.

    7. Replace all existing text with the following:

      {
      "target": "run_existing_window_command", 
      "id": "repl_python_run",
      "file": "config/Python/Main.sublime-menu"
      }
      
    8. Cntrl + S or save as "C:\Users[username]\AppData\Roaming\Sublime Text 3\Packages\User\SublimeREPL-python.sublime-build" updating username or path as needed. This should be wherever your settings and builds are stored by Sublime Text.

    9. Go to Tools, Build System, select SublimeREPL-python.

    10. All done--now to test. Open or create a simple python file, having a *.py extension and save it wherever desired.

    11. Make sure the file is open and selected in Sublime Text. Now, when you press Cntrl + B to build and run it, it will open another tab, titled "REPL [python]", executing and displaying the results of your python code.

    If you would like to go a step further, I highly recommend making the follow changes, to allow Sublime to reload your executed python in the same window, when you press Cntrl+B (Build), instead of it opening a new tab each time:

    Add the following line in the "repl_python_run" command in (Preferences, Browse Packages) SublimeREPL\config\Python\Main.sublime-menu, right before the "external_id": "python" argument:

    "view_id": "*REPL* [python]",
    

    and then to change the line:

    if view.id() == view_id
    

    into:

    if view.name() == view_id
    

    in SublimeREPL\sublimerepl.py.

提交回复
热议问题