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).
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.
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.
Search for python in the search bar and press enter. Click install on the first option (the extension created by Microsoft.)
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.
