Using Visual Studio Code (VS Code) as an IDE with the Enthought Deployment Manager (EDM)

Install VS Code

VS Code can be downloaded and installed from this page.

 

Install Microsoft's Python Extension for VS Code

After you start VS Code, install Microsoft's Python extension directly from VS Code's default welcome page (Customize => Tools and Languages => Python). For reference, the name of this extension is "ms-python.python". It can also be installed from the VS Code Extensions Marketplace.

Python Extension Settings Recommendations

The Python extension has many settings; most of these are personal preferences. Here are a few basics; we plan to add more suggestions in the future. 

To open settings.json, the easiest way is to type Ctrl-Shift-P (Cmd-Shift-P on Mac) and then type Open Settings (JSON) in the Command Palette that appears at the top of VS Code.

 For Mac and Linux users, the most important setting is python.venvFolders; setting this correctly ([".edm/envs"]) should help get VS Code to recognize your EDM-installed Python environments. Windows users should refer to the specific Windows notes below.

The following is a simple sample settings.json file for VS Code:

{
    "python.linting.flake8Enabled": true,
    "python.linting.flake8Args": [
        "--max-line-length=120",
    ],
    "python.linting.pylintEnabled": false,
    "files.trimTrailingWhitespace": true,
    "[markdown]": {
        "files.trimTrailingWhitespace": false
    },
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
    "editor.rulers": [80, 120],
    "editor.hover.enabled": true,
}

Ctags Recommendation

To make navigating through the code easier, we recommend that Universal Ctags be installed along with VS Code. If Ctags is installed and available on the system path, the Python plugin will automatically use Ctags to generate the tags file needed to navigate through your code to class and function definitions. At least for Python, there is no need for a separate Ctags plugin.

For Windows users, get the latest compiled release from Universal Ctags. It will be a zip file that simply has to be unzipped into a directory. We recommend that you unzip it into your user Documentsctags directory. Afterwards, make sure that this directory is listed in  your Windows environment variable PATH.

Installation notes for MacOS using brew can be found on Homebrew Tap for Universal Ctags.

Linux users will need to clone the Git repository and compile as documented on Universal Ctags.

To use:

  • Select a class or function name in your code, type Ctrl-T, and then select one of the definitions listed in the drop-down at the top of VS Code.

 

Using with Windows

Currently Visual Studio Code does not automatically recognize EDM-installed Python environments on Windows. Until this is fixed, making the following change in the Windows registry will make Visual Studio recognize an EDM environment.

1) Copy the following into a text file.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Python\edm_vscode.enthought.com]
"SupportUrl"="https://support.enthought.com"
"DisplayName"="EDM VSCode managed environments"

[HKEY_CURRENT_USER\Software\Python\edm_vscode.enthought.com\python3]
"DisplayName"="python3"
"SupportUrl"="https://support.enthought.com"
"SysVersion"="3.6.5"
"Version"="2.1.9.3717"
"SysArchitecture"="64bit"

[HKEY_CURRENT_USER\Software\Python\edm_vscode.enthought.com\python3\InstallPath]
@="C:\\Users\\USERNAME\\.edm\\envs\\python3"
"WindowedExecutablePath"="C:\\Users\\USERNAME\\.edm\\envs\\python3\\pythonw.exe"
"ExecutablePath"="C:\\Users\\USERNAME\\.edm\\envs\\python3\\python.exe"

2) Replace the USERNAME in "C:\Users\USERNAME" to fit your actual username (and, possibly, the location of the user directories on disk).

3) Replace all references to python3 with the name of your actual EDM environment (i.e., the name of the directory found under C:\Users\USERNAME\.edm\envs which stores the environment you wish to access).

4) Save the updated file on disk as fix_vscode_for_EDM.reg

5) In Windows Explorer, double-click on this file; then allow Windows to make changes to the registry.

6) Restart VS Code, load a Python file, and verify that you can see the EDM Python environment in the Python selector on the lower-left portion of the VS Code window.

General Python Package Recommendations

The following command should be run for each EDM environment that will be used with VS Code, to install flake8:

edm install -e <environment-name> flake8

The flake8 package is a Python linter (syntax checker) that is known to VS Code; installing it will stop VS Code's reminders to select a linter. An added benefit is that linting code while editing is generally a good practice.

Have more questions? Submit a request

Comments

Powered by Zendesk