{"record":{"id":"9dfade196355bb83","repo":"xtekky/gpt4free","slug":"install-docx-requirements-pip-install-u-g4f-f","errorCode":null,"errorMessage":"Install \"docx\" requirements | pip install -U g4f[files]","messagePattern":"Install \"docx\" requirements \\| pip install -U g4f\\[files\\]","errorType":"exception","errorClass":"MissingRequirementsError","httpStatus":null,"severity":"warning","filePath":"g4f/tools/files.py","lineNumber":134,"sourceCode":"\n\ndef supports_filename(filename: str):\n    if filename.endswith(\".pdf\"):\n        if has_pypdf2:\n            return True\n        elif has_pdfplumber:\n            return True\n        elif has_pdfminer:\n            return True\n        raise MissingRequirementsError(\n            f'Install \"pypdf2\" requirements | pip install -U g4f[files]'\n        )\n    elif filename.endswith(\".docx\"):\n        if has_docx:\n            return True\n        elif has_docx2txt:\n            return True\n        raise MissingRequirementsError(\n            f'Install \"docx\" requirements | pip install -U g4f[files]'\n        )\n    elif has_odfpy and filename.endswith(\".odt\"):\n        return True\n    elif has_ebooklib and filename.endswith(\".epub\"):\n        return True\n    elif has_openpyxl and filename.endswith(\".xlsx\"):\n        return True\n    elif filename.endswith(\".html\"):\n        if not has_beautifulsoup4:\n            raise MissingRequirementsError(\n                f'Install \"beautifulsoup4\" requirements | pip install -U g4f[files]'\n            )\n        return True\n    elif filename.endswith(\".zip\"):\n        return True\n    elif filename.endswith(\"package-lock.json\") and filename != FILE_LIST:\n        return False","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/tools/files.py#L116-L152","documentation":"supports_filename raises MissingRequirementsError when a .docx file is passed but neither python-docx (docx) nor docx2txt is installed. Like the PDF case, Word-document support is an optional 'files' extra in g4f.","triggerScenarios":"Attaching a .docx to a g4f request without having installed python-docx or docx2txt in the active environment.","commonSituations":"Base g4f install without extras; CI images that prune optional deps; activating the wrong virtualenv.","solutions":["pip install -U 'g4f[files]'.","Or install one backend: pip install python-docx (or docx2txt).","Confirm with: python -c 'import docx'.","As a workaround, save the document as .txt/.pdf(with backend) before attaching."],"exampleFix":"# before\npip install g4f\n\n# after\npip install -U 'g4f[files]'","handlingStrategy":"validation","validationCode":"from g4f.tools.files import supports_filename\nsupports_filename('notes.docx')  # raises MissingRequirementsError if no docx backend","typeGuard":"from g4f.errors import MissingRequirementsError\n\ndef docx_backend_available() -> bool:\n    for mod in ('docx', 'docx2txt'):\n        try:\n            __import__(mod)\n            return True\n        except ImportError:\n            continue\n    return False","tryCatchPattern":"from g4f.errors import MissingRequirementsError\ntry:\n    supports_filename('notes.docx')\nexcept MissingRequirementsError as e:\n    raise SystemExit('Run: pip install -U g4f[files]') from e","preventionTips":["Install 'g4f[files]' where documents are used","Pre-flight supports_filename() on user uploads","Restrict accepted upload types in your UI to those your install supports","Pin file-parsing deps in requirements.txt"],"tags":["missing-dependency","docx","extras","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}