Search code examples
pythonimportmodulepython-importlangchain

Langchain: ModuleNotFoundError: No module named 'langchain'


When I write code in VS Code, beginning with:

import os
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI
from langchain.document_loaders import TextLoader

I am met with the error: ModuleNotFoundError: No module named 'langchain'

I have updated my Python to version 3.11.4, have updated pip, and reinstalled langchain. I have also checked sys.path and the folder C:\\Python311\\Lib\\site-packages in which the Langchain folder is, is appended.

EDIT: Langchain import works when I run it in the Python console (functionality works too), but when I run the code from the VSCode run button it still provides the ModuleNotFoundError.

Has anyone else run into this issue and found a solution?


Solution

  • For future reference, I'm fairly sure this error was caused by pip installing files in the incorrect directory. Make sure the target directory is where your sys.path folder is, as sometimes these can vary! Thanks to everyone who provided advice.