gpt4 book ai didi

azure - 为什么只有 Python 3.8 - Azure ML 内核可以在笔记本中找到 openai 模块

转载 作者:行者123 更新时间:2023-12-03 05:12:41 27 4
gpt4 key购买 nike

Azure ML Studio中,我创建了一个笔记本,安装了一些包并尝试运行代码

!pip install -r requirements.txt

以上工作

! pip show openai

pip show openai 的结果

Name: openai
Version: 0.25.0
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f88b8d8888978a8cb897889d969991d69b9795" rel="noreferrer noopener nofollow">[email protected]</a>
License: None
Location: /anaconda/envs/azureml_py38/lib/python3.8/site-packages
Requires: typing-extensions, pandas, requests, openpyxl, pandas-stubs, tqdm, numpy
Required-by:

代码

import openai
import re
import requests
import sys
from num2words import num2words
import os
import pandas as pd
import numpy as np
from openai.embeddings_utils import get_embedding, cosine_similarity
from transformers import GPT2TokenizerFast

#API_KEY = os.getenv("AZURE_OPENAI_API_KEY")
API_KEY = "somekey"
#RESOURCE_ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT")
RESOURCE_ENDPOINT = "https://someendpoint/"
openai.api_type = "azure"
openai.api_key = API_KEY
openai.api_base = RESOURCE_ENDPOINT
openai.api_version = "2022-12-01"

url = openai.api_base + "/openai/deployments?api-version=2022-12-01"

r = requests.get(url, headers={"api-key": API_KEY})

print(r.text)

我发现只有 Python 3.8 Azure ML 可以找到 openai 模块。当我选择其他内核时,出现错误 moduel openai not found。为什么?

选择其他内核时出错

ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 import openai
2 import re
3 import requests

ModuleNotFoundError: No module named 'openai'

enter image description here

最佳答案

只需确保 pip 命令使用正确的前缀即可。就我而言,我在安装 openai 时运行了“%pip”而不是“!pip”。

使用“%pip”,软件包将安装在与笔记本相同的环境中,而不是安装在 shell 中

关于azure - 为什么只有 Python 3.8 - Azure ML 内核可以在笔记本中找到 openai 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75981077/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com