无法导入langchain.agents.load_tools

huangapple go评论70阅读模式
英文:

Cannot import langchain.agents.load_tools

问题

我尝试使用LangChain Agents,但无法导入load_tools。
版本:`langchain==0.0.27`

我尝试了以下方法:

```python
from langchain.agents import initialize_agent
from langchain.llms import OpenAI
from langchain.agents import load_tools

显示输出:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-36-8eb0012265d0> in <module>
      1 from langchain.agents import initialize_agent
      2 from langchain.llms import OpenAI
----> 3 from langchain.agents import load_tools

ImportError: cannot import name 'load_tools' from 'langchain.agents' (C:\ProgramData\Anaconda3\lib\site-packages\langchain\agents\__init__.py)

<details>
<summary>英文:</summary>

I am trying to use LangChain Agents and am unable to import load_tools.
Version: `langchain==0.0.27`

I tried these:



from langchain.agents import initialize_agent
from langchain.llms import OpenAI
from langchain.agents import load_tools

shows output 

ImportError Traceback (most recent call last)
<ipython-input-36-8eb0012265d0> in <module>
1 from langchain.agents import initialize_agent
2 from langchain.llms import OpenAI
----> 3 from langchain.agents import load_tools

ImportError: cannot import name 'load_tools' from 'langchain.agents' (C:\ProgramData\Anaconda3\lib\site-packages\langchain\agents_init_.py)



</details>


# 答案1
**得分**: 2

我使用Python 3.7.9时遇到了同样的问题,我改为下载Python 3.10.10后问题得到解决。

<details>
<summary>英文:</summary>

I had the same problem using python 3.7.9, I downloaded python 3.10.10 instead and it worked.

</details>



# 答案2
**得分**: 1

这篇帖子已经有1个月了,在Langchain年里基本上相当于1年。很多事情都发生了变化。请尝试更新到最新版本:

= to this
langchain==0.0.134
from langchain.agents import load_tools
tool_names = [...]
llm = ...
tools = load_tools(tool_names, llm=llm)


<details>
<summary>英文:</summary>

This post is 1 month old which is basically 1 year in langchain years. Alot has changed. Try updating to the latest version 

  

    &gt;= to this 
    
    langchain==0.0.134


    from langchain.agents import load_tools
    tool_names = [...]
    llm = ...
    tools = load_tools(tool_names, llm=llm)

</details>



# 答案3
**得分**: 1

我曾经遇到一个类似的问题,尝试通过 `pip install langchain[all]` 安装 langchain 以及所有集成。

这样安装后,我得到了一个较旧的 langchain 版本,甚至无法导入 `langchain.agents.load_tools` 模块,因为它并不存在。

后来,我通过运行 `pip install langchain --upgrade` 来升级到最新版本的 langchain,问题得到了解决。

随后,我成功按预期导入了它,使用了 `from langchain.agents import load_tools`。

<details>
<summary>英文:</summary>

I had a similar issue installing langchain with all integrations via `pip install langchain[all]`.

This installed some older langchain version and I could not even import the module `langchain.agents.load_tools` since it did not exist.

I just fixed it with a langchain upgrade to the latest version using `pip install langchain --upgrade`.

After that, I was able to import it with `from langchain.agents import load_tools` as expected.

</details>



huangapple
  • 本文由 发表于 2023年2月24日 11:22:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75552338.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定