-1

I installed openai successfully. I also checked it in pip list. But when I wrote import openai it's showing error (no module named openai). I tried some stackoverflow solutions, but they are not working.

If I run my code it is showing this error message below:

Traceback (most recent call last):
  File "/home/al/Projects/python projects/project_name/main.py", line 8, in <module>
    import openai
ModuleNotFoundError: No module named 'openai'

Now what is the solution?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • DO you have more python version installed on your PC? Maybe you installed openai on Python and you running script with another. – Gren Man Feb 22 '23 at 19:41

3 Answers3

0

I'd suggest that you check if it has anything to do with your environment, if you're working with IDE such as Pycharm they usually are set to default to create a new virtual environment, hence no package from global installation is carried over, check your package installation: Make sure that you installed openai in the correct environment.

K4nj
  • 114
  • 4
0

There were problem on openai package for python 3.10 At first should check if in the project, python version and package version for python is same. If not, then fix it by selecting correct version (3.10). If yes, then reinstall the package. Sometime could be that, you have to reinstall python on your device. after that, just go to terminal and try this pip3 install openai you can also install it from IDE. For this go to settings --> python interpreter --> click on the + icon --> search for openai --> and then install it. Hope the problem will be solved!

-1

Are you running the python script in the same (conda) environment as in which you installed the package?

Perhaps the package path wasn't added/recognised. Try adding it manually:

path_to_pkg = '..'  # add directory of openai package 
import sys
sys.path.append(path_to_pkg)
import openai
Thijs
  • 433
  • 8