L2 - Import Error


ImportError Traceback (most recent call last)
Cell In[16], line 2
1 import os
----> 2 from utils import get_openai_api_key
4 openai_api_key = get_openai_api_key()
5 os.environ[“OPENAI_MODEL_NAME”] = ‘gpt-3.5-turbo’

ImportError: cannot import name ‘get_openai_api_key’ from ‘utils’ (C:\Users\flore\utils.py)

Are you running this in your own environment, if so you need an OPENAI key. If not try to reset the kernel, and hopefully you haven’t deleted any of the util files by mistake!

Thanks. I am running on my own environment. I have set an open AI key. Still getting this error.

Hi @Naama_Ben-Oliel_Rone

Follow the comment mentioned by Mubsi in the below link

Regards
DP

1 Like

Thanks! I found the utils.py where you guided me.
The thing is that I try to run things locally and not via the notebook. I use mac Visual Studio Code. How can I make this utils.py available?
Should I update the $PATH somehow? … What do u suggest me doing?

did you download the utils py files and all the necessary files from the instructions mentioned by Mubsi? in your local computer?

:frowning: i didn’t see it. Where can I please find the guidelines? This would be fantastic.

You need to follow the same guidelines mentioned in the above comment by Mubsi.

If you are unable to understand his comments then first download all the files use File==Open options and then download all the files.

Check this another comment which explains you the steps with images for your better understanding.

Let me know if you are still not understanding.

Regards
DP

1 Like

Hi
I did not really get the last step in this
ImportError: cannot import name ‘get_openai_api_key’ from ‘utils’
after I put the utils file in the same location , how do I set the google api key in the .env location?

In the same location where you have the utils.py file, just create a .env.txt file where you should enclose your OpenAI API Key:

OPENAI_API_KEY=“your_openai_api_key_here”

Hoping this can help you.

1 Like

Hi,
I still get the same error

ImportError: cannot import name ‘get_openai_api_key’ from ‘utils’

the utils file,.env file and mynotebook is in the same location

Since the kind of error seems to be related to the import from utils.py file, two suggestions to solve this issue could be the following:

  1. Copy and paste the contents of the utlis.py file into your noteboook and print your api key to verify whether is correctly imported in your notebook. Please see screenshot:

  2. Load directly the open_api_key from the .env file