运行openai遇到:module ‘openai‘ has no attribute ‘ChatCompletion‘ 解决方案
•
Python
问题描述:
运行openai编写的代码,发现报如下错误:
Traceback (most recent call last):
File "文字输入_prompt.py", line 40, in
ans = openai_reply('openai secret key')
File "文字输入_prompt.py", line 18, in openai_reply
response = openai.ChatCompletion.create(
AttributeError: module 'openai' has no attribute 'ChatCompletion'
出现原因
openai安装版本不是最新导致,更新到最新版本就可以解决。(最新版需要到0.27.0)

解决方案
把openai更新到最新版就可以解决:
- 自动安装:pip3 install –upgrade openai
- 或者手动安装:
- 从:https://pypi.org/project/openai/#files下载openai-0.27.0-py3-none-any.whl
- 然后安装:pip3 install openai-0.27.0-py3-none-any.whl
参考地址:https://github.com/openai/openai-python/issues/246
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/b328504146.html
