Python development environment in SublimeText4

Web Technology Digital Transformation Technology Artificial Intelligence Technology Natural Language Processing Technology Semantic Web Technology Deep Learning Technology Online Learning & Reinforcement Learning Technology Chatbot and Q&A Technology User Interface Technology Knowledge Information Processing Technology Reasoning Technology Programming Python Navigation of this blog

Summary

Python will be a general-purpose programming language with many excellent features, such as being easy to learn, easy to write readable code, and usable for a wide range of applications Python was developed by Guido van Rossum in 1991.

As a relatively new language, Python can utilize a variety of effective programming techniques, including object-oriented programming, procedural programming, and functional programming. It is also widely used in web applications, desktop applications, scientific and technical computing, machine learning, artificial intelligence, and other fields because of the many libraries and frameworks available. Furthermore, it is cross-platform and runs on many operating systems such as Windows, Mac, and Linux, etc. Python is an interpreted language, which means that it does not require compilation and has a REPL-like structure, which speeds up the development cycle.

In this article, we will discuss how to set up a Python development environment with SublimeText 4 and VS code.

Python development environment in SublimeText4

Sublime Text is a highly customizable, cross-platform text editor implemented using Python, with numerous plug-ins and themes Sublime Text 4 was released on May 21, 2021. It is the latest version of the Sublime Text series and the first major update in two and a half years. The new version features GPU acceleration for interface rendering and enhanced auto-completion.

The Python development environment using SublimeText is based on “Sublime-Build,” which is used to run the code. To modify the code, you can use it via SublimeRepl or terminus/sendcode.

To build and run the code in python3, use

  1. Go to Tools→Build System→New Build System and enter the following and save it as Python3.sublime-build (for /Users/XXX/python3, type “which python3” in the terminal (on a mac, substitute In the case of windows, use “where python3”) to find the location of the path and assign it to the path).
    {
        "cmd": ["/Users/XXXXXXX/python3", "-u", "$file"],
        "selector": "source.python",
        "file_regex": "file "(...*?)", line ([0-9]+)",
        "env": {"LANG": "ja_JP.UTF-8"}
    }
  2. You can build and run it with “command” and “B” (on mac, “ctrl” and “B” on windows).

For use with SublimeRepl.

  1. Install SublimeRepl using Package Control. (In the menu, select “Tools” → “Command Pallet” → type install → “Package Control:Install Package” → “SublimeRepl”, or select “Shift”, “Command”, “P” (on a mac) → type install → “Install Package Control:Install Package” → “SublimeRepl”)
  2. Configure Python environment settings for SublimeRepl: Preference→Browse Packages to show Sublime text packages in the Finder. Copy config/Python/Main.sublime-menu in the SublimeREPL folder and create a folder like SublimeREPL/config/Python/ in the User folder and paste Main.sublime-menu in the Python folder. Paste the sublime-menu and edit its contents as follows: The two locations /Users/XXX/python3 should work by finding the path in which(mac) as in the above build.
    [
         {
            "id": "tools",
            "children":
            [{
                "caption": "SublimeREPL",
                "mnemonic": "r",
                "id": "SublimeREPL",
                "children":
                [
                    {"caption": "Python",
                    "id": "Python",
    
                     "children":[
                        {"command": "repl_open",
                         "caption": "Python 3",
                         "id": "repl_python3",
                         "mnemonic": "p",
                         "args": {
                            "type": "subprocess",
                            "encoding": "utf8",
                            "cmd": ["/Users/ユーザー名/xxx/python3", "-i", "-u"],
                            "cwd": "$file_path",
                            "syntax": "Packages/Python/Python.tmLanguage",
                            "external_id": "python",
                            "extend_env": {"PYTHONIOENCODING": "utf-8"}
                            }
                        },
                        {"command": "repl_open",
                         "caption": "Python 3 - IPython",
                         "id": "repl_python_ipython3",
                         "mnemonic": "p",
                         "args": {
                            "type": "subprocess",
                            "encoding": "utf8",
                            "autocomplete_server": true,
                            "cmd": {
                                "osx": ["/Users/ユーザー名/xxx/python3", "-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"
                            }
                        }
                        }
                    ]}
                ]
            }]
        }
    ]
  3. View→Layout→Column2 to display the layout in two parts, edit the python file on the left side (or open a new file with “command” and “N” to write code), Tools→sublimeREPL→Python→Python3 to make the REPL work on the right side tab. (If the sendcode plugin is included), “command” and “enter” will send the specified part in the right tab to the REPL for evaluation.

Next, we describe how to set up a Python environment in VS code.

VS code stands for visual studio code, a free text editor provided by microsoft that currently has the largest market share among programmers. The following is a step-by-step guide to development.

  1. To use Clojure with VS code, first install VS code (install the Japanese language plugin if necessary), then go to View→extensions and input python (or View→extensions and input python) and install it.
  2. Next, specify the folder where you want to create a new project with File→Open Folder, and open a new terminal with terminal→new terminal in order to open a terminal in that folder.
  3. Once the terminal opens, create a new Clojure project directory. Example: “mkdir python-test01”.
  4. In the terminal, type “cd python-test01″ to move to the newly created python-test01 directory
  5. Create a new python file “python-test01.py”
  6. Type “python3 python-test01.py” in the terminal to run it.

コメント

タイトルとURLをコピーしました