Visual Studio Code

A popular IDE for developing and debugging code, you can have VS Code automatically detect and recommend the right runtime for your project. This allows you you to work with the security and compliance assurances that your ActiveState project already has directly from your IDE.

Before you begin

Before you can use your ActiveState projects Python interpreter in your VS Code environment, make sure the following conditions are met.

  1. The State Tool is installed on your local machine and is updated to V.36 or later. To update your State Tool, open your command terminal and enter state update.If you have installed the State Tool after opening VS Code you will need to restart VS Code for the changes to take effect.

  2. You have the newest version of the VS Code Python extension installed (version 2023.5.10672245 or later). Click here to learn more about updating VS Code extensions.

Setting up your IDE

Begin by creating a Python file in your project, or opening an existing Python file. If this is a new file you may be prompted to select an interpreter, or if it is an existing file you can select a new interpreter using the VS Code Command Palette.

To access the “Select Interpreter” drop down from the Command Palette, press Shift + Ctrl + P on Windows and Linux or Shift + Cmd + p on macOS and click Python: Select Interpreter.

alt_text

This will automatically generate a list of all of the interpreters available on your machine (including those provided by ActiveState). Click to select your preferred interpreter and begin working on your file.

alt_text

After making your selection your new interpreter will be displayed at the bottom of the VS Code window (“andrewd-activestate/PythonWindows3’:ActiveState” shown above).

Working with an ActiveState project

When working with an ActiveState project folder containing your project’s activestate.yaml file, the associated project’s interpreter will be automatically chosen as the default interpreter (or the “recommended” interpreter) for that file.

You can verify this by opening the VS Code Command Palette (Shift + ctrl + P on Windows and Linux, shift + cmd + p on macOS) and click Python: Select Interpreter to check that the correct interpreter has been selected. The interpreter associated with your project will be listed with a star next to the name and a “Recommended” tag.

alt_text

If your interpreter does not appear in the list

If your preferred ActiveState interpreter is not immediately available in the “Select Interpreter” dropdown see below for solutions.

  1. If the ActiveState plugin is not visible in your Python extension you may need to restart or Update your version of VS Code.
  2. After opening your project, your interpreter may not be immediately available. The plugin for the extension searches for new runtimes approximately every 30 seconds, so you may need to wait until your new interpreter is recognized in the system before restarting your VS Code and trying again.
  3. To check that the State Tool is installed correctly in your IDE go to extensions > Python > Feature Contributions and look for python.activeStateToolPath under the “Settings” list.

alt_text

  1. There may be a problem with the State Tool not registering on the user’s $PATH or %PATH% variable. To enter the absolute path to the State Tool’s executable go to File > Preferences> Settings and search for ”State Tool”. Enter the absolute path to the State Tool executable in the field shown.
  2. The Python interpreter of your project may need to be updated, as Python versions before 3.7 may not be compatible with the extension’s Python libraries. To learn more about updating your language version click here.
  3. You can manually enter the path to your project’s interpreter follwing these steps.
  • Open a command terminal and, working from the directory containing your project’s activestate.yaml file (or a subdirectory of that directory) and enter
state export env

This will return the path to the executable shown below.

alt_text

  • Copy the path shown and create a new Python file or open an existing one in VS Code.
  • Enter Shift + Ctrl + P on Windows and Linux (Shift + Cmd + p on macOS) to open the Command Palette and click Python: Select Interpreter > + Enter interpreter path..
  • Paste the path to the executable into the field shown and press Enter