运行openai遇到:module ‘openai‘ has no attribute ‘ChatCompletion‘ 解决方案

问题描述:

运行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遇到:module ‘openai‘ has no attribute ‘ChatCompletion‘ 解决方案_第1张图片

解决方案

把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

你可能感兴趣的:(python,开发语言)