Issue with deploying due to langchain_community.vectorstores

Hi, for some reason when I deploy my app on Streamlit, I get the following error:

ModuleNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Traceback:

File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 589, in _run_script
    exec(code, module.__dict__)File "/mount/src/gen_ai/PDF_Chat/app.py", line 7, in <module>
    from langchain_community.vectorstores import FAISS
ModuleNotFoundError: No module named 'langchain_community'

It seems like its not able to find that library but when I run locally, everything works as intended so I’m confused what the issue is.

The issue seems to be that langchain-community is not installed.

Yes but how do I fix this? Like how should I install it for it work when deployed via stremlit

Since it works locally, it’s installed on my desktop.

You use a requirements file. See more in the documentation:

Yes, I have already added that:

Im not sure why the “langchain_community” library is not getting installed by Streamlit, can this be an issue from Streamlit ?

The logs should tell you what happened, but I guess it is because it doesn’t exist.

Review the material you have been studying. What made you think that you had to install langchain_community? I think you want langchain-community instead.

The logs mention this:

[09:52:54] 🐍 Python dependencies were installed from /mount/src/gen_ai/PDF_Chat/requirements.txt using uv.
Check if streamlit is installed
Streamlit is already installed
[09:52:56] 📦 Processed dependencies!



────────────────────── Traceback (most recent call last) ───────────────────────
  /home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptru  
  nner/script_runner.py:589 in _run_script                                      
                                                                                
  /mount/src/gen_ai/PDF_Chat/app.py:7 in <module>                               
                                                                                
      4 from langchain.text_splitter import RecursiveCharacterTextSplitter      
      5 from langchain_google_genai import GoogleGenerativeAIEmbeddings         
      6 import google.generativeai as genai                                     
  ❱   7 from langchain_community.vectorstores import FAISS                      
      8 from langchain_google_genai import ChatGoogleGenerativeAI               
      9 from langchain.chains.question_answering import load_qa_chain           
     10 from langchain.prompts import PromptTemplate                            
────────────────────────────────────────────────────────────────────────────────
ModuleNotFoundError: No module named 'langchain_community'

Umm isn’t that the same thing? cause I checked the API documentation and it shows this: langchain_community 0.0.16 — 🦜🔗 LangChain 0.1.4

So when calling it in the python script I did :
from langchain_community.vectorstores.faiss import FAISS

and in the requirements file, I have added it as “langchain-community”

But I still get the same error

Unfortunately you skipped the part where the installed packages are listed.

That’s the right thing to do, as far as I can tell. If there is nothing in the logs related to the installation of langchain-community, you may need to reboot or redeploy the application.

Ok, the langchain-community hasnt been installed for some reason:

 + jsonschema-specifications==2023.12.1
 + kubernetes==30.1.0
 + langchain==0.2.6
 + langchain-core[2024-06-28 13:01:00.998055] ==0.2.10
 + langchain-google-genai==1.0.7
 + langchain-text-splitters==0.2.2
 + langsmith==0.1.82
 + markdown-it-py[2024-06-28 13:01:00.998178] ==3.0.0
 + markupsafe==2.1.5

Can this be an issue from Streamlit’s side for this package? cause I’ve reboot the app + restarted my desktop multiple times and still I’m getting the same issue.

Maybe the langchain-community is not recognized by Streamlit. Can this be mentioned to the team ?

The package can be installed in streamlit cloud without issues, I have installed it as well as many other people.

Maybe the requirements file is not where it should be, maybe there is another requirements file that conflicts with the one you are editing, maybe the requirements file doesn’t have what you think it has…

Ok, it works now!!

I just have one question about the code that I have on github.

I have a .env file with the google API key present, how do I have the app work without disclosing my API key ?

This is how you manage secrets in streamlit cloud:

Got it. thanks!