Version: 13.0

    Show / Hide Table of Contents

    Installation and Configuration

    The following is a comprehensive guide on using the Python programming language to write scripts for MASTA. It details the steps involved to get up and running with a version of Python that is compatible with MASTA, along with information on making the most out of Python scripting with MASTA.

    Installing Python

    A MASTA-compatible version of Python must first be installed to use the Python scripting functionality. To see which versions we currently support, check the mastapy distribution on PyPi.

    For installation we recommend downloading a stand-alone Python interpreter.

    Downloading and Installing Python

    Python can be downloaded from the Python website. Make sure you download a suitable version for MASTA and follow the installation instructions.

    Verifying Python is Installed

    Once Python has finished installing it needs to be verified to ensure it was installed correctly.

    • Start by opening Command Prompt (On Windows, search for cmd and press enter).

      Typing "cmd" into the windows search bar and selecting Command Prompt from the "Best Match" results
      Figure 1 - Searching for cmd on Windows.

    • In Command Prompt, type py -0p and press enter. A list of Python versions should appear including the one you just installed.

      Typing "python" into Command Prompt and the resulting Python Version
      Figure 2 - Running the python command.

    Configuring a Code Editor

    To be able to write a Python script, a suitable code editor is required. For Python specifically, we recommend using Microsoft’s Visual Studio Code due to its wide language support and extensibility. Visual Studio Code can be officially extended to support the Python language, allowing for code highlighting and formatting, Intellisense, linting, debugging, Jupyter Notebooks and more.

    Other editors may be used, such as Spyder, but these are not as flexible for integrating with MASTA. The rest of this guide assumes Visual Studio Code has been installed.

    Setting Python up in Visual Studio Code

    Make sure to download and install Visual Studio Code before proceeding. Once Visual Studio Code is installed, open the application and familiarise yourself with the layout. There is some brilliant documentation available online provided by Microsoft, including introductory videos, that you can use to learn the software.

    To be able to use Python with Visual Studio Code an extension is needed. This can be installed using the Extensions tab inside Visual Studio Code:

    • Select the Extensions tab in Visual Studio Code.

      Selecting the Extensions tab in Visual Studio Code
      Figure 3 - Selecting the Extensions tab

    • Search for python in the search bar and press enter. Click install on the first option (the extension created by Microsoft.)

      Entering python into the search and clicking install on the first option
      Figure 4 - Installing the Python extension

    You may also be prompted to install pylint. This is an optional linter installation and is not required for Python to work in Visual Studio Code, but is useful for automatically spotting programming errors.

    Verifying Visual Studio Code is using the correct version

    Once the extension is installed, verify the correct Python interpreter is being referenced by Visual Studio Code. You can do this by selecting the Python interpreter on the status bar (the blue bar at the bottom of the window), then selecting your Python installation from the drop-down menu that appears. See the images below. For this guide Python 3.7.1 was used but your version may be different. Your version can be checked by following the steps in the section Verifying Python is Installed.

    A drop-down menu in Visual Studio Code, listing the available Python versions to be made active
    Figure 5 - Selecting the correct Python version in Visual Studio Code

    • Click on the status bar where it tells you the currently selected Python interpreter. For this to appear, a Python file must be open in the editor. If you do not have one, create a new file and save it to your Python Solutions directory.

    • Select the correct Python version from the drop-down menu that appears at the top of the window.

    In This Article
    • Installing Python
      • Downloading and Installing Python
      • Verifying Python is Installed
    • Configuring a Code Editor
      • Setting Python up in Visual Studio Code
        • Verifying Visual Studio Code is using the correct version
    Back to top