安装openai环境 步骤及问题解决
安装openai环境,使用大模型。解决报错:ERROR: No matching distribution found for pandas>=1.2.3、 解决报错AttributeError:module 'openai' has no attribute'Chatcompletion'
·
1 按照官网安装
官网介绍很简单,使用pip即可安装成功
pip install openai
但是,按照官方demo调用时,
import openai
openai.api_key ="your_api_key" # 已申请的apikey
response = openai.Chatcompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role":"user","content":"哈喽,你好吗"}
],
temperature=0
)
报错如下:
提示错误:AttributeError:module 'openai' has no attribute'Chatcompletion'
2 排查错误,发现可能是由于Openai版本较低引起
# 查看版本号0.8.0
pip show openai
# 参考其他成功版本号是0.10.3,于是
pip install openai==0.10.3
# 报错内容大致如下
ERROR: Could not find a version that satisfies the requirement pandas>=1.2.3 (from openai) (from versions:0.1 .......)
ERROR: No matching distribution found for pandas>=1.2.3
3 排查问题是高版本pandas需要python3.8.因此搭3.8环境(如果环境ok,可忽略此步骤)
# 打包3.8环境
conda create -n ${your_env_name} python=3.8
# 激活打包环境
conda activate ${your_env_name}
4 在python3.8环境安装
# 升级版本
pip install openai==0.10.3
# 安装成功后,调用代码仍然报错:
提示错误:AttributeError:module 'openai' has no attribute'Chatcompletion'
5 升级版本号
# 将其升级到0.27.7
pip install --upgrade openai
BINGO
更多推荐




所有评论(0)