No module named 'openai'

I thought I’d play around with some python connected to GPT-3.
I am getting the following after launching jupyter notebook on my machine, after doing
pip install openai (which reports back that openai is installed correctly)
I reviewed many online resources, but all assume that “import openai” works. Such as
the official one from OpenAI:

`ModuleNotFoundError Traceback (most recent call last)
in
1 import os
----> 2 import openai
3
4 openai.api_key = os.getenv("<openai_key>")
5 …

ModuleNotFoundError: No module named ‘openai’

`

Has anyone seen this behavior? Maybe it is a jupyter thing. I tried a general Google search as well with no luck (although there were some links to Gym). Relaunching jupyter didn’t solve it.

1 Like

Check the virtual environment and also PWD/CWD of the Jupyter instance.

1 Like

Probably your pip points to a different version of python than your notebook launcher

2 Likes

Yes, @daveshapautomator thanks for the links. I need more hacking. My pip and python are in miniconda. Here is the start of the notebook:

Thanks to both of you for suggestions and fixes.

The basic solution was to make things consistent, as was suggested. I did 'conda install jupyter" because I was using another version of jupyter (which jupyter). Then I obtained an error in authorization, so I went with the traceback suggestion of

openai.api_key = "key"
 rather than
# openai.api_key = os.getenv("key")

Now I am getting useful Json. Now to parse it for something meaningful.

3 Likes

I am running it from the command prompt. Had to set the PATH:
export PATH=“/git/openai-quickstart-python:${PATH}”

2 Likes