RobotGuide
Hands-on/From zero to your first Python script: terminal lesson one

Hands-on 1 / 4

From zero to your first Python script: terminal lesson one

For anyone who has never installed an environment or opened a terminal, this is the first step up. No Linux, no GPU, nothing to buy throughout — just an ordinary laptop.

1–2 h7 stepszero-experience

Math: middle-school mathCoding: zero starting point (this tutorial teaches exactly that)Hardware: an ordinary laptop

What you will have in hand when done

A computer with Python installed; able to use the command line to enter folders, run scripts, and install packages; and a first taste of 'errors are nothing to panic about' — read the error, locate it, fix it: it is a mechanical process.

The other three tutorials on this site all assume you can do these things. This one turns the assumption into fact: every step is a button you can click or a command you can type, and every step has a 'what you must see to pass'.

Before you start

You needVersion / notes
Play with a lab bench first and see what your future code will be controlling

Contents

  1. Open the terminal: type instead of clicking
  2. Install Python: remember to check Add to PATH
  3. First script: two lines of code
  4. Errors are nothing to fear: reading a traceback is a mechanical process
  5. Install packages: pip is your toolbox
  6. Plot the first curve: f(x) = x²
  7. The end is also the start: where to go next
01

Open the terminal: type instead of clicking

The terminal (command line) is the way of operating the computer by typing; every tool in the robotics world lives here. On Windows press Win+R, type cmd and press Enter; on macOS use Spotlight (Cmd+Space) and type Terminal. Two of the most common commands first: cd to enter a folder, and dir (Windows) / ls (macOS) to list files.

terminal / code
cd Desktop
dir     :: list files in the current folder on Windows
ls      # list files in the current folder on macOS

You pass when you see this

After pressing Enter, the listed file names include files you recognize on your Desktop.

Stuck?

SymptomMost likely causeWhat to do
The command prints but nothing seems to happenThe input method is stuck in Chinese modeSwitch back to English (Shift toggles); the terminal only accepts English commands
cd Desktop says the path cannot be foundThe system language is not Chinese, so the Desktop folder has an English name other than DesktopFirst type just cd and press Enter (back to the home directory), then type dir / ls to see the actual names
02

Install Python: remember to check Add to PATH

Open a browser, go to python.org and download the installer (on Windows choose 'Windows installer (64-bit)'). The first checkbox in the Windows installer, 'Add python.exe to PATH', must be checked — 90% of 'python is not recognized as an internal or external command' comes from missing it. Close the installer when done.

terminal / code
python --version

You pass when you see this

The terminal prints a Python version of 3.11 or higher.

Stuck?

SymptomMost likely causeWhat to do
It says 'python is not recognized as an internal or external command'Add to PATH was not checked during installationRun the installer again, choose Modify, check Add to PATH, and keep clicking Next
macOS prints Python 2.xThe old version bundled with the systemInstall the new version from python.org and verify with python3 --version
03

First script: two lines of code

Create a new text file on the Desktop and rename it to hello.py (not hello.txt). Open it in Notepad, paste the two lines below, and save. Back in the terminal (which should still be in Desktop), run it.

terminal / code
# contents of hello.py
print("hello, robot")
for i in range(3):
    print("step", i)

# run in the terminal
python hello.py

You pass when you see this

It prints hello, robot and three lines of step x.

Stuck?

SymptomMost likely causeWhat to do
It says hello.py cannot be foundThe file is actually named hello.py.txt (Windows hides extensions by default)In File Explorer open 'View → Show → File name extensions' and remove the .txt
SyntaxError: invalid characterQuotes or colons were typed as full-width Chinese charactersDelete and retype; quotes, colons and parentheses in code must be half-width English
IndentationErrorThe line under for is not indentedLeave 4 spaces at the start of the second line
04

Errors are nothing to fear: reading a traceback is a mechanical process

Create an error on purpose: change print to prin and run again. The terminal prints a block of red text (a traceback). Reading it takes two steps: look at the last line (what the error is), and look at the first line at the top (where it is). Fix it and run again — once the 'error → locate → fix' loop is smooth, you are ahead of half of all beginners.

terminal / code
prin("oops")   # intentional error

# fixed
print("fixed")

You pass when you see this

Within one minute you can: state the cause (NameError: name 'prin' is not defined) → locate the line → fix it → run it through.

Stuck?

SymptomMost likely causeWhat to do
You cannot make sense of the red textA first encounter with a traceback feels like a disaster movieLook at only two places: the last line is the cause, and the line number the arrow ↑ points to is the scene. Ignore the other lines for now
05

Install packages: pip is your toolbox

In the Python world, tools are installed with pip. Install two you will certainly need: numpy (the foundation of scientific computing) and matplotlib (plotting). After installing, verify they really arrived with one command.

terminal / code
pip install numpy matplotlib
python -c "import numpy; print(numpy.__version__)"

You pass when you see this

It prints the numpy version (2.x).

Stuck?

SymptomMost likely causeWhat to do
pip is not recognized as an internal or external commandA PATH problem or an old PythonUse python -m pip install numpy matplotlib instead
Download is slow or times outThe default index is overseasSwitch to a domestic mirror: pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
06

Plot the first curve: f(x) = x²

Create plot.py: use numpy to make a series of x, compute y=x², and plot it with matplotlib. The parabola in the window that pops up is the same shape as the paraboloid described in /math/grad/ on this site — your first 'robot tuning curve'.

terminal / code
# contents of plot.py
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-3, 3, 100)
y = x ** 2
plt.plot(x, y)
plt.title("f(x) = x^2")
plt.show()

python plot.py

You pass when you see this

A window pops up with a symmetric parabola and the correct title.

Stuck?

SymptomMost likely causeWhat to do
The script exits instantly, no window appearsA graphics backend problemAdd plt.savefig("out.png") before plt.show(); getting the image file also counts as passing
Chinese titles render as squaresThe default font has no Chinese glyphsUse an English title for now; font configuration is something to tangle with later
07

The end is also the start: where to go next

By now you have: terminal, Python, error handling, package installs, plotting. The next step is the gazebo-arm tutorial on this site, but it needs Linux — a decision of another order of magnitude (installing Ubuntu dual-boot or WSL2). You do not need to decide today; just know the order: get fluent with Python locally first (modify plot.py to plot x³ and sin(x)), then touch Linux.

You pass when you see this

You can state what your next step is and what it requires.

Stuck?

SymptomMost likely causeWhat to do
Cannot choose between dual-boot and WSL2You have not looked into either yetDo neither yet. Repeat everything in this tutorial once more on your own; once you can run it all without looking at this page, go read the 'before you start' checklist of gazebo-arm

Acceptance checklist

Without looking at notes or chat history, complete each item below on your own — only then is the tutorial really done.

Keep learning

Next: build a six-axis arm in Gazebo (needs Linux)Math bridge: how to read the curve you just plottedIn-browser lab benches: install nothing

Other tutorials

Build a six-axis arm in Gazebo from scratch and make it obey you

URDF → gz-sim → gz_ros2_control → MoveIt 2, one chain walked end to end, about 6 hours

6–8 h

Train a grasping policy from scratch: MuJoCo + SAC + HER

First get the arm to reach the target, then learn to pick it up. Training runs with a single command, about 5 hours

5–6 h

Isaac Lab parallel training: 4096 environments at once

From environment setup to exporting a deployable policy, about 4 hours (excluding training time)

4 h + training