langchain icon indicating copy to clipboard operation
langchain copied to clipboard

jinja2 is not optional

Open dalazx opened this issue 2 years ago • 3 comments

langchain was installed via pip

Traceback (most recent call last):
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/test.py", line 1, in <module>
    from langchain.agents import load_tools, initialize_agent, AgentType
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/__init__.py", line 6, in <module>
    from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/agents/__init__.py", line 2, in <module>
    from langchain.agents.agent import (
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/agents/agent.py", line 17, in <module>
    from langchain.chains.base import Chain
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/chains/__init__.py", line 2, in <module>
    from langchain.chains.api.base import APIChain
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/chains/api/base.py", line 8, in <module>
    from langchain.chains.api.prompt import API_RESPONSE_PROMPT, API_URL_PROMPT
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/chains/api/prompt.py", line 2, in <module>
    from langchain.prompts.prompt import PromptTemplate
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/prompts/__init__.py", line 3, in <module>
    from langchain.prompts.chat import (
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/prompts/chat.py", line 10, in <module>
    from langchain.memory.buffer import get_buffer_string
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/memory/__init__.py", line 11, in <module>
    from langchain.memory.entity import (
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/memory/entity.py", line 8, in <module>
    from langchain.chains.llm import LLMChain
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/chains/llm.py", line 11, in <module>
    from langchain.prompts.prompt import PromptTemplate
  File "/Users/oleksandrdanshyn/github.com/dalazx/langchain/langchain/prompts/prompt.py", line 8, in <module>
    from jinja2 import Environment, meta
ModuleNotFoundError: No module named 'jinja2'

since prompt.py is one of the fundamental modules and it unconditionally imports jinja2, jinja2 should probably be added to the list of required dependencies.

dalazx avatar Apr 18 '23 21:04 dalazx

Just ran into the same issue.

setu4993 avatar Apr 18 '23 22:04 setu4993

I see this issue is due to #3013. I opened a pull request in #3123 that makes langchain only imports jinja2 when jinja2 prompt template is used. Thanks for pointing that out.

outday29 avatar Apr 19 '23 02:04 outday29

Should be fixed in the latest release.

setu4993 avatar Apr 19 '23 06:04 setu4993

Hi, @dalazx! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, the issue you reported was about the jinja2 module not being imported in the prompt.py module, which caused a ModuleNotFoundError. It seems that the issue has been resolved in the latest release. Another user, @outday29, opened a pull request that addressed the issue by adding jinja2 to the list of required dependencies and making langchain only import jinja2 when the jinja2 prompt template is used.

If this issue is still relevant to the latest version of the LangChain repository, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself. If we don't hear from you within 7 days, the issue will be automatically closed.

Thank you for your contribution to LangChain! Let us know if you have any further questions or concerns.

dosubot[bot] avatar Sep 17 '23 17:09 dosubot[bot]