Knowledge Base

Welcome to the Robotical knowledge base! These pages will help you get the most out of your Marty

Marty Images



Setting up Python for Marty Programming

Step 1: Installing Python

First you need to make sure you have the Python programming language and the pip command installed on your computer.

There are two versions of Python; Python 2 and Python 3. We need the newer Python 3. Throughout this guide, you will see references to “python and pip commands”. On some systems, these might refer to Python 2 and you might need to substitute python and pip for python3 and pip3 respectively.

If you already know how to open a terminal window (command prompt), you can check that these are installed by running python --version and pip --version. The former should output something like Python 3.8.6 and the output of the latter should start with something like pip 20.1.1 and end with (python 3.8). Make sure the Python versions match (in this case, both are Python 3.8). Also make sure that the Python version is at least 3.6.0. On Linux, this check looks like this:

If you are not sure how to perform the above check or you don't have Python installed (the commands output an error instead of a version number), you can go to installpython3.com and follow the instructions for your OS. Remember to also try python3 and pip3 if python or pip don't work.

If you are setting up Python on a Raspberry Pi, have a look here:

Setting Up Python on a Raspberry Pi

If you have used Python before, feel free to use your favourite installation method.

Step 2: Installing the martypy Python Library

You should now be familiar with a terminal window (command prompt) so open one up and type the following:

pip install martypy

This will install the martypy Python library onto your computer and it should show something like this to indicate success:

Collecting martypy
  Using cached martypy-2.0-py2.py3-none-any.whl (49 kB)
Collecting pyserial
  Using cached pyserial-3.4-py2.py3-none-any.whl (193 kB)
Installing collected packages: pyserial, martypy
Successfully installed martypy-2.0 pyserial-3.4

Updating martypy:

(No need to do this if you just installed martypy.)

If something doesn't work, you can try updating martypy - maybe it has already been fixed. Updating is very similar to installing martypy. To get the newest version, run the following command:

pip install --upgrade martypy

Step 3: Making sure it worked

Launch IDLE (usually installed along with Python) – this is an application that can be used for executing Python commands interactively.

If you don't have IDLE, don't worry! You can also just open up a terminal window (command prompt) and type the following:

python

(Or python3, on some systems.)

Now you have a Python Shell in front of you. It is great for executing short commands and trying out a few things. For now, let's just verify that martypy was installed correctly.

Type import martypy and hit Enter. A new set of three arrows (>>>) should appear and now you can type martypy.__version__. The output should be something like '2.2.0'. For example:

To do something more exciting with your Python Shell, have a look at First Steps With Python. If you would like to write a bit more than just trivial Python programs, you will need a good text editor so you you can also carry on with the next section while you are setting things up.

If you started your Python Shell from a terminal (command prompt), you can go back there by typing exit().

Setting up a Text Editor

Python programs are written in plain text so you will also need a text editor to write them.

For Windows, Mac and Linux the best choice (if you don’t have a personal preference already) is VisualStudio Code which is freely available.

On the Raspberry Pi, raspberrypi.org recommend Thonny which should already be installed.

If you are installing VisualStudio Code and are presented with the following screen, we recommend selecting these options:

  • Add "Open with Code" action to Windows Explorer file context menu
    • This will make it easier to open your Python scripts by right-clicking them.
  • Add "Open with Code" action to Windows Explorer directory context menu
    • If you make a directory with all your MartyPy projects, this will let you navigate around it from within VS Code if you right-click the directory and "Open it with Code."
  • Add to PATH (requires shell restart)
    • This should be selected by default. It makes it easier to launch VS Code in some cases.

If you are using Visual Studio Code then there are extensions which make programming in Python very convenient - there is a nice tutorial on code.visualstudio.com. You can also try out the Pylance extension which makes Python programming even more convenient. At the time of writing, Pylance is still just a Preview version, meaning there might still be problems with it and you may want to hold off installing it untill it's fully ready.

Now you are ready to start programming Marty