C1W4_Assignment - name 'os' is not defined and name ‘plt’ is not defined

I keep getting the following feedback when submitting the work. As a result, Failed Grade.

There was a problem compiling the code from your notebook. Details:
name 'os' is not defined

I have import statement on the notebook though. Any ideas? Thanks ahead.

import os

Same thing is happening for matplotlib although I have imported those libraries.

There was a problem compiling the code from your notebook. Details:
name ‘plt’ is not defined

Please click my name and message your notebook as an attachment.

Hi Balaji, I have sent the notebook to you.

Hi Balaji, Finally I passed it. Seem like I need to declare the import statements in the same cells using those libraries.

Only one question. Why?

I used to import such libraries on top of notebook in all of my previous learning. It doesn’t raise such errors though. Thanks ahead.

You have to explicitly run or execute the cells in the Jupyter Notebook. Just having the lines of code sitting at the top of the file isn’t sufficient to bring those types into the namespace.

interesting… I was able to run and complete successfully while I was coding without having imports and usage lines in the same cell. Error only happens when I do submission though. Do they compile/run differently?

Please message me the notebook you submitted.

As long as the learner adds code only where required, everything should work as expected. Only when the learner follows notebook instructions and doesn’t pass the assignment, the grader is at fault.

A few things that can result in a failing grade are:

  1. Adding / removing new cells
  2. Adding / removing print statements
  3. Changing function signature / return type
  4. Adding global imports when you’re expected to work with the existing ones.


@wokee The grader only executes the code in your submitted notebook’s cells that contain graded functions. If you added new dependencies inside those cells/functions, especially if the imports for them are in other cells, no guarantees the autograder will have imported the necessary packages.