How to Solve NameError: name 'commands' is not defined

Solution: Import the 'commands' module

# Add the following line to the top of your code
import commands

 

For more information:
Python commands