# ModuleNotFoundError: No module named 'distutils'

**URL:** <https://community.crewai.com/t/modulenotfounderror-no-module-named-distutils/5512>\
**Category:** CrewAI Community Support\
**Tags:** tools\_issues, crewai\
**Created:** [April 25, 2025, 8:38am UTC](https://community.crewai.com/t/modulenotfounderror-no-module-named-distutils/5512 "2025-04-25T08:38:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![invesTIPS](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/investips/32/3494_2.png) [@invesTIPS](https://community.crewai.com/u/invesTIPS)\
**Post date:** [April 25, 2025, 8:38am UTC](https://community.crewai.com/t/modulenotfounderror-no-module-named-distutils/5512/1 "2025-04-25T08:38:55Z")

</div>

Hi!

When trying to execute “crewai run” I receive the following error:  
_ModuleNotFoundError: No module named ‘distutils’_

I’ve tried different Python version (10, 11, 12, 13…) but keep receiving the same error message.  
I’ve installed ‘setuptools’ as I understood this could help, confirmed it is installed:  
`python3.11 -c "from distutils.util import strtobool; print(strtobool('yes'))"`

but still receiving the same error message:  
_ModuleNotFoundError: No module named ‘distutils’_

Anyone has run into this issue or has any idea of how to fix it? Tried ChatGPT but still nothing 😅

Thank you.

---

<div class="post-metadata">

**Author:** ![Tristannica](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/tristannica/32/3499_2.png) [@Tristannica](https://community.crewai.com/u/Tristannica)\
**Post date:** [April 25, 2025, 11:00pm UTC](https://community.crewai.com/t/modulenotfounderror-no-module-named-distutils/5512/2 "2025-04-25T23:00:04Z")

</div>

Encountered the same issue; looks like `distutils` is deprecated from python 3.11 onwards. This is the workaround I’ve employed, which builds the `distutils/strtobool` functionality directly into your project eliminating any dependency:

Within your project directory, edit the following file:

`~/.venv/lib/python3.12/site-packages/crewai_tools/tools/file_writer_tool/file_writer_tool.py`

Overwrite the contents of `file_writer_tool.py` with:

```auto
import os
# from distutils.util import strtobool
# from setuptools._distutils.util import strtobool
def strtobool(val: str) -> bool:
    """Convert a string representation of truth to true (1) or false (0).

    True values are 'y', 'yes', 't', 'true', 'on', and '1';
    False values are 'n', 'no', 'f', 'false', 'off', and '0'.
    Raises ValueError if 'val' is anything else.
    """
    val = val.lower()
    if val in ("y", "yes", "t", "true", "on", "1"):
        return True
    elif val in ("n", "no", "f", "false", "off", "0"):
        return False
    else:
        raise ValueError(f"Invalid truth value: {val}")
from typing import Any, Optional, Type

from crewai.tools import BaseTool
from pydantic import BaseModel

class FileWriterToolInput(BaseModel):
    filename: str
    directory: Optional[str] = "./"
    overwrite: str = "False"
    content: str

class FileWriterTool(BaseTool):
    name: str = "File Writer Tool"
    description: str = "A tool to write content to a specified file. Accepts filename, content, and optionally a directory path and overwrite flag as input."
    args_schema: Type[BaseModel] = FileWriterToolInput

    def _run(self, **kwargs: Any) -> str:
        try:
            # Create the directory if it doesn't exist
            if kwargs.get("directory") and not os.path.exists(kwargs["directory"]):
                os.makedirs(kwargs["directory"])

            # Construct the full path
            filepath = os.path.join(kwargs.get("directory") or "", kwargs["filename"])

            # Convert overwrite to boolean
            kwargs["overwrite"] = bool(strtobool(kwargs["overwrite"]))

            # Check if file exists and overwrite is not allowed
            if os.path.exists(filepath) and not kwargs["overwrite"]:
                return f"File {filepath} already exists and overwrite option was not passed."

            # Write content to the file
            mode = "w" if kwargs["overwrite"] else "x"
            with open(filepath, mode) as file:
                file.write(kwargs["content"])
            return f"Content successfully written to {filepath}"
        except FileExistsError:
            return (
                f"File {filepath} already exists and overwrite option was not passed."
            )
        except KeyError as e:
            return f"An error occurred while accessing key: {str(e)}"
        except Exception as e:
            return f"An error occurred while writing to the file: {str(e)}"

```

Run `crewai run` again and you should be good to go. If you’re using OpenAI, make sure you have billing turned on for your API usage and a payment method added (_this is independent of ChatGPT billing_).

---

<div class="post-metadata">

**Author:** ![Rasha\_Salim](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rasha_salim/32/3462_2.png) [@Rasha\_Salim](https://community.crewai.com/u/Rasha_Salim)\
**Post date:** [April 28, 2025, 1:47pm UTC](https://community.crewai.com/t/modulenotfounderror-no-module-named-distutils/5512/3 "2025-04-28T13:47:57Z")

</div>

Thanks this helped resolved the issue

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex025/uploads/crewai/original/1X/ecda97e72f77c7100e0a761444b1c991925cc789.png) [@system](https://community.crewai.com/u/system)\
**Post date:** [May 8, 2025, 6:46pm UTC](https://community.crewai.com/t/modulenotfounderror-no-module-named-distutils/5512/4 "2025-05-08T18:46:01Z")

</div>

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