#No Module Named openai

77 messages · Page 1 of 1 (latest)

slow prism
#

I'm trying to use the GPT api, but for some reason my terminal keeps giving me the following error: "ModuleNotFoundError: No module named 'openai'" Would anyone know how to fix this?

Here is my full code:

import os
import openai

openai.api_key = "sk-xxxx"

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="Create names for my Border Collie dog.",
  temperature=0.7,
  max_tokens=256,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0
)

print(response)
void gate
#

Was talking to a friend of mine about a hackathon, sorry about the wait

#

Anyways what version of Python are you running when running the script?

#

Python 2 or Python 3?

#

You'd run python for Python 2, and python3 for Python 3

#

@slow prism

slow prism
#

I installed it recently

void gate
# slow prism python 3

Make sure then that you have the shebang at the top of the file:

#!/usr/bin/env python3
import openai

openai.api_key = "sk-xxxx"

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="Create names for my Border Collie dog.",
  temperature=0.7,
  max_tokens=256,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0
)

print(response)
#

And that you use pip3 to install openai

#

so pip3 install openai

slow prism
#

It says Requirement already satisfied

void gate
#

Alright, then run this script I mentioned with the shebang

slow prism
#

ModuleNotFoundError: No module named 'openai'

steel beacon
#

@cerulean magnet (someone i know that has the same problem)

void gate
#

Go into the python3 environment and import openai there

#

Probably a Python environment issue.

slow prism
#

Okay I will try to find that on my computer

void gate
#

Go into the terminal and type out python3

slow prism
#

ohhhhhh

#

kk

#

Python 3.9.12 (main, Apr 5 2022, 01:53:17)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin

void gate
#

Try to import openai there

#

So type in import openai

slow prism
#

It's loading

void gate
#

Alright, if it's loading without errors, then the package has been installed.

slow prism
#

kk now what

void gate
#

type in exit()

#

And then go to, in your terminal, where your script is.

slow prism
#

I can run the API in VSCode right?

void gate
#

More or less, go into the directory / folder where the script is, and type in python3 <INSERT-FILE-NAME>.py

#

Replace <INSERT-FILE-NAME> with the name of the file

slow prism
#

This is where I'm at so far

void gate
#

Alright, so go back to your terminal, and in the user home directory (e.g., type in cd ~), run this line: touch test.py

slow prism
void gate
#

with a space

slow prism
#

kk now what

void gate
#

type in code test.py

slow prism
#

zsh: command not found: code

void gate
#

Ah alright, type in open . then

#

Don't forget the period

slow prism
#

kk

void gate
#

And then right click the file and select "open with VSCode"

#

Or well "Open With>VSCode"

slow prism
#

kk

#

im in it

void gate
#

Copy and paste the code you had before.

slow prism
#

done

#

it says the same error

void gate
#

Hmm, it might just be an Anaconda environment issue

slow prism
#

Do I need a newer version of Anaconda

#

I'm on 1.9.0

void gate
slow prism
#

Okay

void gate
#

conda activate base

slow prism
#

kk

void gate
#

Now go into the Python3 terminal using python3

slow prism
#

kk

void gate
#

import openai

slow prism
void gate
#

run exit()

slow prism
#

it says syntax error

void gate
#

Just type in exit()

slow prism
#

kk done

#

Hmm still says in VSCode that there isn't an openai module

void gate
#

You don’t want to run the code in the VSCode terminal

#

Try running it in the regular terminal you ran the conda activate command from

slow prism
#

Idk what’s wrong. Thanks for trying to help me

west flint
#

vuex

craggy island
#

I used the same code

#

it worked for me

#

all i did was pip install openai

#

simple