# I am facing error in the week 1 assignment

**URL:** <https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092>\
**Category:** Introduction to TF for Artificial Intelligence ...\
**Tags:** week-module-1\
**Created:** [April 18, 2023, 8:08pm UTC](https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092 "2023-04-18T20:08:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Usman\_Afzal](https://avatars.discourse-cdn.com/v4/letter/u/e480ec/32.png) [@Usman\_Afzal](https://community.deeplearning.ai/u/Usman_Afzal)\
**Post date:** [April 18, 2023, 8:08pm UTC](https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092/1 "2023-04-18T20:08:03Z")

</div>

I am facing this error ""There was a problem compiling the code from your notebook. Details:  
name ‘keras’ is not defined "  
while I click on the library then unable to edit

---

<div class="post-metadata">

**Author:** ![canxkoz](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/canxkoz/32/24458_2.png) [@canxkoz](https://community.deeplearning.ai/u/canxkoz)\
**Post date:** [April 18, 2023, 9:33pm UTC](https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092/2 "2023-04-18T21:33:41Z")

</div>

Hello Usman Afzal,  
Thanks a lot for sharing your issue here. I will do my best to answer and resolve your issue. Please feel free to share screenshots if the issue persists.

“name ‘keras’ is not defined” indicates that the Keras module is not properly imported. If possible, open up a new cell on your notebook and type “`!pip install keras`” or type “`pip install keras`” on your terminal.

Once Keras is intalled, it can be imported using the following line:  
`import keras`

Please check for spelling errors on your notebook. keras might have been misspelled on the import statement.

If the error message persists, it is necessary to check the Jupyter notebook kernel and make sure that it is using the correct Python environment. The kernel can be changed by selecting “Kernel” from the Jupyter notebook menu and then selecting the desired kernel.

Please feel free to share the issue still exists by a screenshot of your notebook. Please make sure that you are running all of the cells in your notebook.

I am here to help, feel free to reply on this thread regarding your issue.  
Best,  
Can Koz

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [April 18, 2023, 9:46pm UTC](https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092/3 "2023-04-18T21:46:37Z")

</div>

Every time you open a notebook, you have to run all of the cells starting from the top. This is because that’s where the packages are imported and the data sets are created.

---

<div class="post-metadata">

**Author:** ![gubertoli](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gubertoli/32/5518_2.png) [@gubertoli](https://community.deeplearning.ai/u/gubertoli)\
**Post date:** [May 31, 2023, 7:56am UTC](https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092/4 "2023-05-31T07:56:08Z")

</div>

The baseline code from the notebook only imports tensorflow with the following:

```auto
import tensorflow as tf

```

However, `keras` is part of the `tensorflow`, thus you can still import it without using `pip`, but with a small change to the syntax seem on the video lesson (prepending with `tf.*`):

- `keras.Sequential` to `tf.keras.Sequential`
- `keras.layers` to `tf.keras.layers`

---

<div class="post-metadata">

**Author:** ![mouliksingh1](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mouliksingh1](https://community.deeplearning.ai/u/mouliksingh1)\
**Post date:** [June 15, 2024, 4:30pm UTC](https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092/6 "2024-06-15T16:30:02Z")

</div>

All you need to do is below import section create a new cell and run ‘from tensorflow import keras’

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [June 15, 2024, 4:40pm UTC](https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092/7 "2024-06-15T16:40:07Z")

</div>

that’s not the right solution as you are not suppose to edit or add any new cell in this assignment or add an import statement in a grade cell.

it is more related to how the layer has been recalled in the tensorflow. also kindly do not respond on such old posts as your response can confuse some other learners.

regards  
DP

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [June 15, 2024, 4:40pm UTC](https://community.deeplearning.ai/t/i-am-facing-error-in-the-week-1-assignment/311092/8 "2024-06-15T16:40:13Z")

</div>

Closed on June 15, 2024, 4:40pm UTC


