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

For context, please see Canopy GUI end of life -- transition to the Enthought Deployment Manager (EDM) and Visual Studio Code

Note: the tools described in this article are usually updated monthly, providing easier use, more capabilities, and bug fixes. VS Code and the Enthought Tools for VS Code will tell you when updates are available. For EDM updates, please check its download page.

If you are installing on a Mac, please also see Using Enthought Python / EDM with VS Code on a Mac.

Sections in this article

Install the Enthought Deployment Manager (EDM) 

Install Microsoft's Visual Studio Code

Install Enthought Tools Extension for VS Code

Create an Enthought Python environment

Activate an Enthought Python environment 

The VS Code Terminal panel

"Linters" and the flake8 package

About Microsoft's Python Extension for VS Code 

Heads-up for Windows users who have another Python on PATH

Additional tips

Install the Enthought Deployment Manager (EDM) 

Product info and download. EDM is Enthought's preferred tool for Python installation and package management. 

Caution -- almost all of EDM's functionality is command-line only.  The separate "EDM" GUI desktop application, which is included with many EDM installers, is not a GUI for general EDM functionality. Rather, this GUI's primary purpose is discovering and installing applications written for and by Enthought consulting customers.

If you encounter an error when starting the EDM GUI: 

  • Unlike the EDM command line, the EDM GUI is not designed for offline / disconnected use. 
  • As of May 2020, some new users may find that EDM GUI crashes when attempting to save settings. In this case, please open a command line (terminal) and type "edm info", after which the EDM GUI should be able to save settings ok.
  • If the EDM GUI gives you a connectivity error when starting it, it is likely that your system needs proxy firewall configuration. This is outside the scope of this article. Since the EDM GUI is not necessary for using EDM and VS Code together, please quit the EDM GUI application and proceed with the rest of this article, or just use EDM from the command line.

Install Microsoft's Visual Studio Code

Product info and download. VS Code is Microsoft's free, open-source, extensible, multi-platform IDE, not to be confused with Microsoft's commercial Visual Studio.

Install Enthought Tools Extension for VS Code

From within VS Code, install Enthought Tools for VS Code.  An easy way to do this is to go to the Extensions / Marketplace tab in VS Code, type "enthought", then select and install the Enthought extension, or you can download the extension separately. It provides an easy interface for installing and working with Enthought Python environments.

Warning: DO NOT ACCEPT the following suggestion if it appears: "Python is not installed. Please download and install Python before using the extension." If you accept this, it could interfere with your Enthought Python environments (see next section).

After installation, the Enthought extension can be used by clicking on the Enthought icon in the VS Code left-side toolbar:

vscode-enthought-extension.png

To see all the Enthought extension commands, open VS Code's Command Palette (Ctrl (Cmd) + Shift + P), then type edm to filter the list. These commands can be invoked by clicking buttons on the UI, or directly from that list.

Create an Enthought Python environment

You can quickly create a new Python environment by using Enthought's curated "GettingStarted" environment bundle, which provides over 140 core packages and is accessible online via the Enthought Extension. Click on the "+" sign next to the bundle's name, then give the target environment a name of your choice:

vscode-enthought-extension2.png

Creating this environment may take between a few minutes and an hour, depending on your network and system speed and especially on your anti-virus settings. After the environment has been created, it will appear in the Environments list at the top left of the Enthought Tools panel. 

Alert: The GettingStarted bundle is only directly available on internet-connected machines. If you are on a machine which is offline or where a firewall is blocking access to EDM, then:

Activate an Enthought Python environment 

When an Enthought Python environment is activated, it will be the Python used when you open a Terminal or when you click the editor's Run button. You can see that it is activated because there will be a bright green dot to the left of the environment's name.

When you use Enthought Tools to create a new environment, it will automatically be activated  for the duration of the session. To re-activate it after restarting VSCode, or to activate a different environment, hover over the environment name, then click the triangular (Play) "Activate" button next to it. 

Troubleshoot: If Enthought Tools shows that environment A is activated, but other parts of VSCode are telling you that there's a different Python active, just deactivate environment A (by clicking on the X next to its name), then reactivate it.

The VS Code Terminal panel

The VS Code Terminal panel usually occupies the lower-right quadrant of the VS Code window. The Terminal panel contains one or more Terminal instances, but it only shows one of these at a time. You can switch between these Terminal instances using the drop-down selector at the upper right of the Terminal panel. For Python programming, you'll mostly use two kinds of Terminal instance:

  • "Python" terminal. Generally, you should reserve this for use by VS Code itself. VS Code uses this terminal whenever you click the Run button at the upper right of a Python script in the VS Code editor. (Pro detail: Enthought Python is not activated in this terminal; instead, whenever you click the Run button, VS Code runs your script here -with a full explicit path to your Python interpreter.)VSC-Python-terminal.png

  • Enthought Python environment terminals, for example "python-class". These are created when you activate an Enthought Python environment in the Enthought Extension for VS Code. Your Enthought Python environment is activated in these terminals, so when you enter any python command, it runs automatically in the- Enthought Python environment:
    VSC-python-class-terminal.pngBecause of this activation, you can directly run commands like these in an Enthought Python terminal instance:
    python myscript.py
ipython
jupyter notebook

"Linters" and the flake8 package

 If a message pops up telling you that pylint is not installed, click "Select linter" and choose flake8 from the list, if it is available.  If it is not yet available, install it.

Flake8 is automatically installed with our default GettingStarted bundle. Otherwise, the following command can be run in each EDM environment that will be used with VS Code:

edm install -e <environment-name> flake8

Background: 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.

About Microsoft's Python Extension for VS Code 

The Enthought extension ensures that Microsoft's Python Extension for VS Code is also installed automatically, so you do not need to install Microsoft's extension yourself. 

The Microsoft 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.

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,
}

 

Heads-up for Windows users who have another Python on PATH

If you have another Python (e.g. from Anaconda, Intel, or python.org) installed on your system and included in your PATH environment variable, then  the "Run" button in the VS Code editor will not work as expected in Enthought Python environments. You may experience errors trying to run many scripts, including those that use numpy or other packages with Python-specific DLL-based components. You may also experience errors running other Python-based VS Code extensions.

A simple test for this situation is to open a Command Prompt window, or a new VS Code Terminal panel, and try to run the python command. It should not succeed. If it does, then you are likely to experience this problem.

Note that it's normal and fine to have conda itself (like edm) on the PATH. The problem is privileging one Python environment over all others, by putting it on the PATH. This can be a problem up even if you are using only conda-based, or only edm-based, Python environments.

Solutions and workarounds

This behavior is inherited from the Microsoft Python extension; we are investigating ways to improve the experience.

1) Please note that having any Python on your PATH when you have multiple Pythons installed is a system configuration bug. The best practice for users who have multiple Pythons installed is not to have any of them on your PATH. For instructions for fixing this, see Editing environment variables on Windows. If this Python is in the system-controlled part of your PATH, then you might require help from a system administrator to remove it.

2) If fixing your PATH is not possible, the cleanest workaround in most cases is to start VS Code from within an already-activated Enthought Python environment. This temporarily places it on the PATH ahead of the other Python. To do that:

  • Completely quit VS Code
  • From the Windows Start Menu, open a Command Prompt window
  • Type edm shell -e your-Python-environment-name which temporarily modifies PATH and the prompt
  • Type code to restart VS Code with these modifications.

(Note that this workaround will fail for some combinations of environment and edm. We are investigating.)

3) Another workaround, which is easy, but somewhat inconvenient, is simply not to use the Run button. Instead, you can run all your scripts manually in VS Code Terminal window where Enthought Python has been activated. You'll know that you are in such a terminal, when you see the environment's name at the top of the VS Code's Terminal panel:

edm-terminal-in-vscode.png

 

Additional tips

See More tips for using VS Code with EDM

 

Please do not enter support requests in article comments

Please use article comments for suggestions to improve the article. For individual support requests, please follow these guidelines.

Have more questions? Submit a request

Comments

Powered by Zendesk