ModuleNotFoundError: No Module Named openai

avatar
作者
猴君
阅读量:0

题意: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.

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

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!