没有名为Openai的模块
我已经使用pip安装OpenAI
在笔记本电脑上安装了OpenAI。
已安装在我的笔记本电脑上,并在我的代码文件所在的同一文件夹上安装后。但是,当我尝试运行代码时,我会得到ImporterRor:no模块名为OpenAI
这是文件中的代码。非常简单:
import openai
openai.api_key = API_KEY
prompt = "Say this is a test"
response = openai.Completion.create(
engine="text-davinci-001", prompt=prompt, max_tokens=6
)
print(response)
我在做什么错?
I've installed openai on my laptop with pip install openai
.
Have installed on my laptop and after installed on the same folder where my code file is. But when I try to run the code I get ImportError: No module named openai
This is the code from the file. Pretty simple:
import openai
openai.api_key = API_KEY
prompt = "Say this is a test"
response = openai.Completion.create(
engine="text-davinci-001", prompt=prompt, max_tokens=6
)
print(response)
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
我遇到了同样的问题,而我所做的一切都是:
首先将OpenAi软件包卸载:
然后我升级了PIP:
然后,我将OpenAPI软件包重新安装
并使用。
I encountred the same problem and all what I did was:
First uninstall the openai package with :
Then I upgraded pip with :
And i re-installed the openapi package with
And it worked.
如果您有多个版本的Python
可以显示PIP已安装OpenAI软件包的位置,则可以运行此命令,
您将在您看到这样的输出中
,pip安装python版本3.8的openai。
因此,如果默认的Python版本为2.7,则在运行Python时进行 import openai ,这将行不通。
您可以将默认的Python版本更改为软件包OpenAI的同一方面,
然后选择正确的版本(我为3.8)。
您也可以尝试为默认Python版本安装OpenAI:
This can happen if you have multiple versions of python
to show where pip has installed openai package, you can run this command
you will have an output like this
as you see, for me pip installs the package openai for the python version 3.8.
so if the default python version is 2.7 for example, when running python then making import openai, this will not work.
you can change the default python version to the same verion of the package openai, use
Then select the correct version (3.8 for me).
you can also try to install openai for your default python version:
最佳答案对我不起作用,但这确实是:
我在Mac上使用VS代码。我必须选择正确的Python解释器。我使用Python 3和PIP3代替PIP。
使用以下方式卸载OpenAI软件包
(请务必使用pip3):
我将OpenAPI软件包重新安装(请务必使用pip3):
Top answer didn't work for me, but this did:
I am using VS code on a mac. I had to select the correct Python interpreter. I am using Python 3 and pip3 instead of pip.
Uninstall the openai package with :
Upgraded pip with (be sure to use pip3):
And i re-installed the openapi package with (be sure to use pip3):
运行以下命令后,
如果使用Visual Studio代码重新启动内核。它对我有用。
After you run the following command
If you are using visual studio code restart your kernal.it worked for me.
对于试图在MacOS上运行它的人(请安装 flask 首先),然后使用
并有效。
For the one who tries to run it on macOS (Please install Flask first), then use
and it works.
尝试它对我有用,替换3.10的Python版本
Try it works for me , replace 3.10 for your python version
尝试在摘要之后放置
- 用户
。此后,错误不会显示&该代码对我来说很好。
Try putting
--user
after the snippet.After this, the error doesn't show up & the code works fine for me.
我试图通过安装Python3的Mac上的VS代码来运行我的OpenAi Python脚本。当我尝试通过按VS代码的Pythance Python扩展程序提供的播放按钮来运行脚本,我一直在获取错误消息
no模块名为OpenAI
。对我有帮助的是,使用标准提示> PIP安装OpenAi OpenAI ,然后通过终端提示
Python3 Script.py
执行我的脚本。I was trying to run my openai python script through VS Code on a Mac with python3 installed. When I tried to run my script by pressing the play button supplied by VS Code's Pylance Python extension I kept getting the error message
No module named openai
.What helped me was, to install openai with the standard prompt
pip install openai
and by executing my script through the terminal promptpython3 script.py
.如果您以admin(或sudo)为adman脚本运行python脚本,则会引发错误Importerror:no模块名为OpenAI。但是使用admin(或sudo),它的运行良好
in case you are running the python script as admin (or sudo) it throws the error ImportError: No module named openai. but with out admin (or sudo) it just runs fine
这可能是临时VS代码错误。尝试关闭应用程序并再次尝试。它对我在Pycharm上效果很好。
我用了这个:
This might be a temporary VS code error. Try closing the app and trying it again. It worked well for me on pycharm.
I used this:
如果有人在模拟器上运行 firebase 时遇到了这个问题:
您必须确保在pyvenv.cfg上设置此配置为'true':
If anyone runs into this problem when running Firebase on an emulator:
You have to make sure this config is set to 'true' on pyvenv.cfg:
我确实在根部的MacOS终端上安装了PIP安装OpenAI,然后该项目随后进行了。
I did pip install openai on the macOS terminal at the root and the project worked afterwards.
在您的IDE上,将OpenAI模块手动添加到解释器中。
问题将得到解决!
对于Pycharm,
请转到文件 - >设置 - >项目 - > Python解释器 - >添加模块(寻找 +符号)
tadaa!
On your IDE , manually add the openai module to the interpreter .
The issue will be resolved !
For Pycharm ,
Go to File -> settings -> project -> python interpreter -> add the module (look for + symbol )
Tadaa !
在使用Pycharm的情况下,面对这个问题,PyCharm为每个项目都保留了单独的执行环境。
我尝试在VSCODE中运行相同的代码,它没有任何错误。
Was facing this issue with using pyCharm, turned out pyCharm maintains separate execution environment for each of the projects.
I tried to run the same code in VSCode, it ran without any error.
就我而言,我再次卸载并安装了OpenAI,但是,我仍然遇到同样的错误。
我发现我的机器上安装了2个Python版本。因此
给了我一个错误
,使用该问题 。请检查您的情况是否也是问题。注意:我使用的是虚拟env,但是我仍然遇到此错误。
In my case I uninstalled and installed openai again, however, I was still getting the same error.
I found out that I had 2 python versions installed on my machine. So executing
Gave me an error, however, using
Solved the issue. Please check if this is the problem in your case too. Note: I was using a virtual env but I was still getting this error.
如果您的Jupyter Lab/Notebook正在运行全部关闭,请关闭终端,通过PIP安装模块并重新启动Jupyter。
因为在Jupyter从另一个终端会话运行时安装模块对我不起作用。
If you have Jupyter lab/notebook running just close it all, shut down the terminal, install the module via pip and restart Jupyter.
Because installing the module while Jupyter was running from another terminal session didn't work for me.