{"id":21338,"library":"file-magic","title":"file-magic","description":"Python front end for libmagic(3) — uses ctypes to wrap libmagic for file type detection. Current version 0.4.1, last released 2016; requires libmagic (system library). Unmaintained; prefer `python-magic` for active development.","status":"deprecated","version":"0.4.1","language":"python","source_language":"en","source_url":"https://github.com/file/file","tags":["file-magic","mime-type","libmagic","file detection"],"install":[{"cmd":"pip install file-magic","lang":"bash","label":"PyPI install"}],"dependencies":[{"reason":"System library (libmagic) must be installed; Linux: apt-get install libmagic1, macOS: brew install libmagic","package":"libmagic","optional":false}],"imports":[{"note":"Top-level import; no submodule needed.","wrong":"","symbol":"magic","correct":"import magic"}],"quickstart":{"code":"import magic\nm = magic.open(magic.MAGIC_NONE)\nm.load()\ntype_ = m.file('/path/to/file')  # e.g., 'ASCII text'\nprint(type_)\n","lang":"python","description":"Basic usage: create a magic cookie, load magic database, detect file type."},"warnings":[{"fix":"Use `python-magic` for new projects.","message":"`file-magic` is unmaintained (last release 2016). Prefer `pip install python-magic` instead, which has a similar API and is actively maintained.","severity":"gotcha","affected_versions":"all"},{"fix":"Install libmagic (e.g., apt-get install libmagic1 on Debian/Ubuntu).","message":"Requires system libmagic installed. If missing, get an OSError or ImportError.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider using `python-magic-bin` or `python-magic` with appropriate binary.","message":"On Windows, libmagic is not preinstalled; need to bundle DLL or use alternative.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Uninstall both and reinstall only one: `pip uninstall file-magic python-magic python-magic-bin` then `pip install python-magic`.","cause":"Both `file-magic` and `python-magic` create a module named `magic`. If both are installed, import may fail or wrong version used.","error":"ImportError: No module named magic"},{"fix":"Install libmagic: on Linux `sudo apt-get install libmagic1` (or equivalent), on macOS `brew install libmagic`.","cause":"System library libmagic is missing.","error":"OSError: libmagic not found"},{"fix":"Encode path if needed: `m.file(bytes(path, 'utf-8'))` or ensure string path works (usual).","cause":"In Python 3, file path must be bytes or string; often happens when passing string to .file() where lib expects bytes.","error":"TypeError: a bytes-like object is required, not 'str'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}