Get Started with MartyPy
Introduction

Posted   —   № 5
Page 1 of 2

Install Python

Python is a programming language, and needs to be installed on your computer before you can use it. How you do this depends on what operating system you’re running on your computer. Here are some good tutorials on how to install Python on specific systems, or how to start using it if it comes pre-installed, like on a RaspberryPi:

Installing MartyPy

MartyPy is a Python library for Marty. Libraries are just collections of code that we’ve written that get all the complicated stuff out of the way, making it easier to use and work with. For example, MartyPy contains the definition of the “walk” function, which can be used to make Marty walk. If you’ve never used Python before, it’s well worth checking out one of the thousands of tutorials and videos online. Most people consider Python one of the easiest programming languages to learn, and a good level-up after mastering Scratch.

Python.org Download Page

Ensure that you have Python installed on your machine, and python virtual environments. Support for virtual environments, or venvs comes bundled with python on soe systems and not other, where they may need to be installed as a second step.

We recommend installing the latest version of Python 3, but Python 2 is also supported, and using pyvenv rather than virtualenv

If you’re using a Linux distribution, use whichever package manager you’d normally use to install python and pyvenv though in all likelihood you’ll already have some version of Python installed.

On a Mac, setup is pretty complex if you don’t already have Homebrew and XCode installed. Again, we’d strongly recommend you go find a tutorial for installing Python on a Mac, then come back - this might be a good start.

For Windows users, Python can be downloaded from python.org: Python Downloads

As a sidenote, if you don’t want to follow through installing MartyPy the ‘proper’ way using a virtualenv, then you can just type pip install martypy and it’ll probably work…

If you don’t use Python for anything else, or are completely new to it then taking the simpler route will be easier for you.

Open a Terminal (Command Prompt). We’ll want to work from a project folder of some sort, so the first thing we’re going to need to do is make an empty directory and go into it:

Let’s make a project folder, which can be called whatever you want - I’m going to go with martypy-tutorial:

Linux/Mac/UNIX
you@computer:~$ mkdir martypy-tutorial
Windows
C:\Users\Username>MKDIR martypy-tutorial

Move into it…

Linux/Mac/UNIX
you@computer:~$ cd martypy-tutorial
Windows
C:\Users\Username>CHDIR martypy-tutorial

Create a new Virtual Environment called VENV:

Linux/Mac/UNIX
you@computer:martypy-tutorial$ pyvenv VENV
Windows
C:\Users\Username\martypy-tutorial>pyvenv VENV

And ‘activate’ it – You’ll have to activate your virtual environment each time you need to use your code and martypy and haven’t already done so in a particular window.

Linux/Mac/UNIX
you@computer:martypy-tutorial$ source ./VENV/bin/activate
Windows
C:\Users\Username\martypy-tutorial>source .\VENV\bin\activate

Finally, we can install martypy:

Linux/Mac/UNIX
(VENV) you@computer:martypy-tutorial$ pip install martypy
Windows
C:\Users\Username\martypy-tutorial>pip install martypy

Once the last step is completed, MartyPy should be installed. To confirm this, we’ll open a Python Shell and try to import the library:

$ python
Python x.y.z (default, Jan 1 1970, 00:00:01)
Type "help", "copyright", "credits" or "license" for more information.
>>> import martypy
>>>

If no errors are displayed, you have successfully installed MartyPy! If you get an error (or Exception) that looks like this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named martypy
>>>

Then Python can’t find martypy. This is most likely because either 1) the Virtual Environment hasn’t been sourced, or 2) because you didn’t pip install martypy.