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

Solution: Import the 'runpy' module

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

 

For more information:
Python runpy