I'm following the tutorial here for using Python2 to interact with Minecraft Pi. Everything is fine up until the "Blocks as Variables" section. Here is my code:

from mcpi import minecraft
from time import sleep

mc = minecraft.Minecraft.create();

dirt = block.DIRT.id

But running this code gives the error for the dirt line:

NameError: name 'block' is not defined

How do I fix this?

closed as off-topic by Bex, Jacobm001, dhruvvyas90, mpromonet, Ghanima Jul 28 '15 at 6:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Bex, Jacobm001, dhruvvyas90, mpromonet, Ghanima
If this question can be reworded to fit the rules in the help center, please edit the question.


The error is in the raspberrypi.org example. It's missing an import. Add the following line and your code should work fine:

from mcpi import block

Not the answer you're looking for? Browse other questions tagged or ask your own question.