Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

remove pkg_resources which was causing issues (#1751)

Brandon Hancock (bhancock_ai)ad916abd7652
diff --git a/src/crewai/cli/cli.py b/src/crewai/cli/cli.py
index 43dc90eed..a1c003631 100644
--- a/src/crewai/cli/cli.py
+++ b/src/crewai/cli/cli.py
@@ -1,7 +1,7 @@
+from importlib.metadata import version as get_version
from typing import Optional
import click
-import pkg_resources
from crewai.cli.add_crew_to_flow import add_crew_to_flow
from crewai.cli.create_crew import create_crew
@@ -25,7 +25,7 @@ from .update_crew import update_crew
@click.group()
[email protected]_option(pkg_resources.get_distribution("crewai").version)
[email protected]_option(get_version("crewai"))
def crewai():
"""Top-level command group for crewai."""
@@ -52,16 +52,16 @@ def create(type, name, provider, skip_provider=False):
def version(tools):
"""Show the installed version of crewai."""
try:
- crewai_version = pkg_resources.get_distribution("crewai").version
+ crewai_version = get_version("crewai")
except Exception:
crewai_version = "unknown version"
click.echo(f"crewai version: {crewai_version}")
if tools:
try:
- tools_version = pkg_resources.get_distribution("crewai-tools").version
+ tools_version = get_version("crewai")
click.echo(f"crewai tools version: {tools_version}")
- except pkg_resources.DistributionNotFound:
+ except Exception:
click.echo("crewai tools not installed")
diff --git a/src/crewai/telemetry/telemetry.py b/src/crewai/telemetry/telemetry.py
index aa0f8b9ff..984a4938d 100644
--- a/src/crewai/telemetry/telemetry.py
+++ b/src/crewai/telemetry/telemetry.py
@@ -6,6 +6,7 @@ import os
import platform
import warnings
from contextlib import contextmanager
+from importlib.metadata import version
from typing import TYPE_CHECKING, Any, Optional
@@ -16,10 +17,6 @@ def suppress_warnings():
yield
-with suppress_warnings():
- import pkg_resources
-
-
from opentelemetry import trace # noqa: E402
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
OTLPSpanExporter, # noqa: E402
@@ -106,7 +103,7 @@ class Telemetry:
self._add_attribute(
span,
"crewai_version",
- pkg_resources.get_distribution("crewai").version,
+ version("crewai"),
)
self._add_attribute(span, "python_version", platform.python_version())
self._add_attribute(span, "crew_key", crew.key)
@@ -308,7 +305,7 @@ class Telemetry:
self._add_attribute(
span,
"crewai_version",
- pkg_resources.get_distribution("crewai").version,
+ version("crewai"),
)
self._add_attribute(span, "tool_name", tool_name)
self._add_attribute(span, "attempts", attempts)
@@ -328,7 +325,7 @@ class Telemetry:
self._add_attribute(
span,
"crewai_version",
- pkg_resources.get_distribution("crewai").version,
+ version("crewai"),
)
self._add_attribute(span, "tool_name", tool_name)
self._add_attribute(span, "attempts", attempts)
@@ -348,7 +345,7 @@ class Telemetry:
self._add_attribute(
span,
"crewai_version",
- pkg_resources.get_distribution("crewai").version,
+ version("crewai"),
)
if llm:
self._add_attribute(span, "llm", llm.model)
@@ -367,7 +364,7 @@ class Telemetry:
self._add_attribute(
span,
"crewai_version",
- pkg_resources.get_distribution("crewai").version,
+ version("crewai"),
)
self._add_attribute(span, "crew_key", crew.key)
self._add_attribute(span, "crew_id", str(crew.id))
@@ -393,7 +390,7 @@ class Telemetry:
self._add_attribute(
span,
"crewai_version",
- pkg_resources.get_distribution("crewai").version,
+ version("crewai"),
)
self._add_attribute(span, "crew_key", crew.key)
self._add_attribute(span, "crew_id", str(crew.id))
@@ -474,7 +471,7 @@ class Telemetry:
self._add_attribute(
span,
"crewai_version",
- pkg_resources.get_distribution("crewai").version,
+ version("crewai"),
)
self._add_attribute(span, "crew_key", crew.key)
self._add_attribute(span, "crew_id", str(crew.id))
@@ -543,7 +540,7 @@ class Telemetry:
self._add_attribute(
crew._execution_span,
"crewai_version",
- pkg_resources.get_distribution("crewai").version,
+ version("crewai"),
)
self._add_attribute(
crew._execution_span, "crew_output", final_string_output