Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anthropic_version = packaging.version.parse(version("anthropic")) AttributeError: module 'packaging' has no attribute 'version' #7283

Closed
1 of 14 tasks
junruxiong opened this issue Jul 6, 2023 · 5 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@junruxiong
Copy link

System Info

When I initialise ChatAnthropic(), it got the error:

anthropic_version = packaging.version.parse(version("anthropic"))
AttributeError: module 'packaging' has no attribute 'version'

Who can help?

@hwchase17 @agola11

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

from langchain.chat_models import ChatOpenAI, ChatAnthropic
llm = ChatAnthropic()

Expected behavior

As shown above.

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jul 6, 2023
@dosubot
Copy link

dosubot bot commented Jul 6, 2023

Answer generated by a 🤖

Answer

I understand that you're encountering an AttributeError: module 'packaging' has no attribute 'version' when you try to initialize ChatAnthropic(). This error suggests that the version attribute is not found in the packaging module. This could be due to an incorrect import statement.

To address this issue, I propose the following steps:

  1. Ensure that the packaging and importlib.metadata modules are installed in your Python environment. You can do this by running the following command in your terminal:
pip install packaging importlib_metadata
  1. In your Python script, import the version attribute from the importlib.metadata module and the parse function from the packaging.version module like this:
from importlib.metadata import version
from packaging.version import parse
  1. Then, you can use the parse function to parse the version of "anthropic":
anthropic_version = parse(version("anthropic"))

This solution should resolve the AttributeError you're experiencing. However, please note that this is one potential solution based on the information provided. If the issue persists, there might be other factors at play.

If you find this solution correct and believe it's a bug that could impact other users, you're encouraged to make a pull request to help improve the LangChain project.

In case this solution doesn't align with your experience, I would recommend upgrading to the latest version of LangChain, as the issue might have been resolved in a more recent update.

Sources


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

@dudesparsh
Copy link
Contributor

I tried to run the same, and I am able to reproduce the same error (AttributeError: module 'packaging' has no attribute 'version')

  1. What's working is the solution suggested by bot i.e.
from importlib.metadata import version
from packaging.version import parse
  1. What might be going wrong in our case is that, package.version is getting confused with importlib.metadata.version and there is a mixup.
  • What we can do to resolve is:
from importlib.metadata import version
from packaging.version import parse

anthropic_version = parse(version("anthropic"))

@baskaryan
Copy link
Collaborator

out of curiosity, what python version are you getting issue with?

baskaryan pushed a commit that referenced this issue Jul 6, 2023
- Description: Solving, anthropic packaging version issue by clearing
the mixup from package.version that is being confused with version from
- importlib.metadata.version.

  - Issue: it fixes the issue #7283 
  - Maintainer: @hwchase17 

The following change has been explained in the comment -
#7283 (comment)
@junruxiong
Copy link
Author

My version is 3.10.12

@dosubot
Copy link

dosubot bot commented Oct 6, 2023

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

Based on the information provided, it seems that the issue you reported was related to an error when initializing ChatAnthropic(), specifically an AttributeError related to the packaging module. I provided a solution suggesting to import the version attribute from the importlib.metadata module and the parse function from the packaging.version module. dudesparsh confirmed that the solution worked for them.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your contribution to the LangChain repository!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Oct 6, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants