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)
我正在尝试导入openai,但它不断抛出错误“未找到模块”。我已经完成了 pip install openai 并下载了它,但它似乎是错误的 python 版本。如何选择正确的 pip 安装位置?我正在使用 VSCode
pip 安装 openai
尝试使用
pip3 install openai
,因为它为 python3 安装 openai,而不是 python2(如果已安装)。如果你只有 python3,pip 和 pip3 基本上是相同的东西(我认为)。
JialeDu 的答案对我有用,但是当我在 Windows 的环境变量中添加了正确的路径到我的 pip 设置后
如果您想从任何位置运行 pip(或其他工具),则需要通过执行以下操作将其安装目录添加为 PATH 环境变量:
1 - 打开控制面板并导航至系统和安全 > 系统 2 - 单击左侧面板上的高级系统设置链接 3 - 单击环境变量。 4 - 在系统变量下,双击变量 PATH。 5 - 单击“新建”,然后添加安装 pip 的目录,例如C:Python33Scripts,然后选择确定。
在使用 openAI 的嵌入库时,我遇到了同样的问题。我不断添加缺少的模块,直到
sklearn
为止。对我有用的是:
pip install scikit-learn
我遇到了同样的问题,但我发现该软件包被安装到较旧的 python 版本的路径中。我通过显式指定 python 版本安装了该模块并解决了问题
!pip3.11安装langchain
而不是
!pip3安装langchain