ModuleNotFoundError: No module named 'langtrace_python_sdk'

I strictly followed installation of langtrace_python_sdk in crewai, set up the project correctly in Langtrace, but I get the error when I run crewai run:

Traceback (most recent call last):
File "/home/theone/Downloads/Zendata/crewai/project_pii/manager_api/.venv/bin/run_crew", line 5, in <module>
    from manager_api.main import run
  File "/home/theone/Downloads/Zendata/crewai/project_pii/manager_api/src/manager_api/main.py", line 1, in <module>
    from langtrace_python_sdk import langtrace
ModuleNotFoundError: No module named 'langtrace_python_sdk'
An error occurred while running the crew: Command '['uv', 'run', 'run_crew']' returned non-zero exit status 1.

I am in a Ubuntu machine, conda environment. The package was installed inside the env, from where I run crewai.

The module is correctly imported in any python script inside the env, but not in crewai run.

I successfully run crewai run without ‘langtrace_python_sdk’

Any ideas on how to solve this issue ?

UPDATE

I solved by copying some packages from my Anaconda environment to crewai .env, but I am wondering if there is a cleaner way to implement this.

I mean, should we treat each crewai project as a brand new environment, and install all necessary libraries in this environment?

Also, other issue, Langtrace is not working with the CrewAI project, only with Default project.

This solved the issue for me:

The ModuleNotFoundError for langtrace_python_sdk in your CrewAI project indicates that the module isn’t accessible within the environment where CrewAI is running. To resolve this issue, follow these steps:

  1. Add langtrace_python_sdk as a Dependency in pyproject.toml:

    • Navigate to your CrewAI project’s directory.
    • Open the pyproject.toml file.
    • Under the [project] section, add langtrace_python_sdk to the dependencies list:
      [project]
      dependencies = [
        "crewai[tools]>=0.95.0,<1.0.0",
        "langtrace_python_sdk>=3.3"
      ]
      
    • Save the file.
  2. Reinstall Project Dependencies:

    • In the terminal, ensure you’re in your project’s root directory.
    • Run the following command to install the updated dependencies:
      crewai install
      
    • This command will set up a virtual environment specific to your project and install all listed dependencies, including langtrace_python_sdk.
  3. Verify the Installation:

    • After the installation completes, run your project:
      crewai run
      
    • If the ModuleNotFoundError persists, ensure that the langtrace_python_sdk is correctly installed in the virtual environment.
  4. Manual Installation (if necessary):

    • If issues continue, manually activate the virtual environment created by CrewAI:
      source .venv/bin/activate
      
    • Then, install the langtrace_python_sdk directly:
      pip install langtrace-python-sdk
      
    • After installation, deactivate the virtual environment:
      deactivate
      
    • Retry running your project with crewai run.

By ensuring that langtrace_python_sdk is listed as a dependency in your project’s pyproject.toml and properly installed within the project’s virtual environment, CrewAI should recognize and import the module without issues.

For more detailed information, refer to the Langtrace AI documentation on integrating with CrewAI: Langtrace AI Docs.

If you encounter further difficulties, consider consulting the CrewAI community forums for additional support.

1 Like

Thanks @cbak, this indeed solved the issue.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.