英文:
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
>= 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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论