Run on your system : python -m pip3 install python-dotenv
create also a .env in your current directory a line : OPEN_API_KEY=‘your key’
If run directly in a jupyter cell, type first an exclamation mark : !pip3 install python-dotenv
File ~\AppData\Roaming\Python\Python310\site-packages\openai\util.py:186, in default_api_key()
184 return openai.api_key
185 else:
→ 186 raise openai.error.AuthenticationError(
187 “No API key provided. You can set your API key in code using ‘openai.api_key = ’, or you can set the environment variable OPENAI_API_KEY=). If your API key is stored in a file, you can point the openai module at it with ‘openai.api_key_path = ’. You can generate API keys in the OpenAI web interface. See https://platform.openai.com/account/api-keys for details, or email support@openai.com if you have any questions.”
188 )
AuthenticationError: No API key provided. You can set your API key in code using ‘openai.api_key = ’, or you can set the environment variable OPENAI_API_KEY=). If your API key is stored in a file, you can point the openai module at it with ‘openai.api_key_path = ’. You can generate API keys in the OpenAI web interface. See https://platform.openai.com/account/api-keys for details, or email support@openai.com if you have any questions.
You need to set up your OpenAI account API key to be able to work. You can set the API key by running the command in Jupyter, as shown in the error message, for example: openai.api_key=your_api_key . If the problem persists, you can refer to OpenAI’s documentation.
It is used to indicate that the command following it should be treated as a shell command, rather than a piece of Python code.
Also, once you have your open ai key, you can just use it as a string literal…no need to set the environment variable, and then no requirement for installing or importing os or dotenv packages. You will, however, need to install redline and panel for later exercises. HTH