ModuleNotFoundError: No Module Named openai
创始人
2024-11-11 08:05:59

题意:Python 无法在环境中找到名为 openai 的模块

问题背景:

import requests from bs4 import BeautifulSoup import openai   #write each line of nuclear.txt to a list with open('nuclear.txt', 'r') as f:     lines = f.readlines()  #remove the newline character from each line lines = [line.rstrip() for line in lines]  #gather the text from each website and add it to a new txt file for line in lines:     r = requests.get(line)     soup = BeautifulSoup(r.text, 'html.parser')     text = soup.get_text()     with open('nuclear_text.txt', 'a') as f:         f.write(text)

I'm trying to import openai, however it keeps throwing the error module not found. I have done pip install openai and it downloads, but it appears to be the wrong version of python. How do I select the correct one for pip to install to? I am using VSCode

我尝试导入 openai 模块,但它一直抛出“模块未找到”的错误。我已经执行了 pip install openai 并且它下载了,但似乎它安装在了错误的 Python 版本上。我该如何为 pip 选择正确的 Python 版本来安装?我正在使用 VSCode。

pip install openai

问题解决:

Follow the steps below to install the openai package for the current interpreter

按照以下步骤为当前解释器安装 openai 包

1. run the following code        运行以下的代码

import sys print(sys.executable)

2. get the current interpreter path        获取当前解释器路径

3. Copy the path and install openai using the following command in the terminal

复制该路径并在终端中使用以下命令安装 openai

C:\WorkSpace\pytest10\.venv\Scripts\python.exe -m pip install openai 

Modify the path in the above command to the interpreter path you got.

将上述命令中的路径修改为你获取的解释器路径。

相关内容

热门资讯

裸辞做“一人公司”,我后悔了 去年这个时候,一位以色列程序员正在东南亚旅行。他顺手把一个在脑子里转了很久的想法做成了产品,一个让任...
南京建成国内首个Pre-6G试... 4月21日,2026全球6G技术与产业生态大会在南京开幕。全息互动技术展台前,一名远在北京的工作人员...
超梵求职受邀参加“2025抖音... 超梵求职受邀参加“2025抖音巨量引擎成人教育行业生态大会”,探讨分享优质内容传播,服务万千学员。 ...
摩托罗拉Razr 2026(R... IT之家 4 月 22 日消息,摩托罗拉宣布新一代 Razr 折叠手机将于 4 月 29 日在美国发...
库克卸任,特纳斯领航:苹果新纪... 苹果首席执行官蒂姆·库克将卸任,硬件工程主管约翰·特纳斯将接任,苹果公司今天宣布此事。 库克将在夏季...