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
pip install openai
CodePudding user response:
Try using pip3 install openai
, as it installs openai for python3, not python2 (if you have it installed). If you only have python3, pip and pip3 are basically the same thing (I think).
CodePudding user response:
Follow the steps below to install the openai
package for the current interpreter
run the following code
import sys print(sys.executable)
get the current interpreter path
Copy the path and install
openai
using the following command in the terminalC:\WorkSpace\pytest10\.venv\Scripts\python.exe -m pip install openai
Modify the path in the above command to the interpreter path you got.