No module named 'tools' when trying to import a custom tool

I run the latest Versions:
crewai==0.86.0
crewai-tools==0.17.0

I create a new crew with:

crewai create crew <crewname>

I start it with:

crewai run

It works perfectly fine.

But when I define a new custom tool and try to import it in the crew.py file, i get this error:

... 
   from tools.custom_tool import ImageGeneratorTool
ModuleNotFoundError: No module named 'tools'
An error occurred while running the crew: Command '['uv', 'run', 'run_crew']' returned non-zero exit status 1.
...

I appreciate any support and hints! <3

Well in my crew.py imports would look something like this:

from crewai import Agent, Crew, Process, Task, LLM

from crewai.project import CrewBase, agent, crew, task, before_kickoff, after_kickoff 
from crewai_tools import SerperDevTool, ScrapeWebsiteTool,  FileWriterTool

from dotenv import load_dotenv
1 Like

I am also have the same issue when defining custom tools. Any solution for that?

How are you importing the tool to your crew.py file?

So this is generally how you’re supposed to import it into your crew.py:

Example:

from aws_infrastructure_security_audit_and_reporting.tools.aws_infrastructure_scanner_tool import AWSInfrastructureScannerTool

So for you:

  1. Look for the name of the folder under src/ and use that as the first portion of the import before .tools.
  2. Then after .tools. add the file name that’s holding your custom tool function(s); in your case, it looks like it is custom_tool
  3. Finish with the import ImageGeneratorTool

Let me know if this is helpful.

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