{"id":8496,"library":"pylibmagic","title":"pylibmagic","description":"pylibmagic is a lightweight Python package designed to simplify the installation and usage of the `libmagic` C library. It provides pre-compiled `libmagic` shared libraries via Python wheels, primarily addressing the common `ImportError: failed to find libmagic` encountered when using other `libmagic` bindings like `python-magic`. The current version is 0.5.0, with releases focusing on expanding Python version and architecture support.","status":"active","version":"0.5.0","language":"python","source_language":"en","source_url":"https://github.com/kratsg/pylibmagic","tags":["file-type-detection","libmagic","bindings","binary-dependencies","wheels"],"install":[{"cmd":"pip install pylibmagic","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"wrong":"from pylibmagic import magic","symbol":"magic","correct":"from pylibmagic import magic"}],"quickstart":{"code":"import pylibmagic\nimport magic\n\n# pylibmagic ensures the underlying libmagic library is available\n# You can inspect the data path it uses:\nprint(f\"pylibmagic data path: {pylibmagic.data}\")\n\n# Now, use the python-magic library as usual\ntry:\n    m = magic.Magic()\n    file_type = m.from_buffer(b\"hello world\")\n    print(f\"'hello world' is detected as: {file_type}\")\n    \n    # Example with a common file type\n    with open(\"temp_text.txt\", \"w\") as f:\n        f.write(\"This is a test file.\")\n    file_type_from_file = m.from_file(\"temp_text.txt\")\n    print(f\"'temp_text.txt' is detected as: {file_type_from_file}\")\n    import os\n    os.remove(\"temp_text.txt\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure 'python-magic' is also installed (`pip install python-magic`).\")","lang":"python","description":"This quickstart demonstrates how to use `pylibmagic` in conjunction with the `python-magic` library. `pylibmagic` ensures that the `libmagic` C library is available for `python-magic` to use, solving common installation issues. After importing `pylibmagic`, you can then proceed to use the `magic` module from `python-magic` as intended."},"warnings":[{"fix":"Ensure both `pylibmagic` and `python-magic` are installed: `pip install pylibmagic python-magic`.","message":"pylibmagic does not provide the 'magic' module directly. Its purpose is to bundle and make the underlying `libmagic` C library accessible. To use the Python bindings for `libmagic`, you typically need to install `python-magic` separately.","severity":"gotcha","affected_versions":"All versions"},{"fix":"On Debian/Ubuntu, install `libmagic1` or `libmagic-dev` (`sudo apt-get install libmagic1`). On macOS, install via Homebrew (`brew install libmagic`). For Windows, `python-magic-bin` might be a more robust solution, or ensure `libmagic` DLLs are correctly placed and match your Python's bitness.","message":"On platforms or architectures without pre-built wheels, `pylibmagic` installation might fail or require system-level `libmagic` installation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that the `libmagic` DLLs and your Python installation are both either 32-bit or 64-bit. Consider using `pip install python-magic-bin` which often includes the correct binaries for Windows.","message":"Using a 32-bit `libmagic` DLL with a 64-bit Python (or vice-versa) on Windows can lead to `WindowsError: [Error 193]`.","severity":"gotcha","affected_versions":"All versions on Windows"}],"env_vars":null,"search_vec":"'0.5.0':54 'address':32 'architectur':63 'binari':72 'binary-depend':71 'bind':45,70 'c':18 'common':34 'compil':24 'current':51 'depend':73 'design':8 'detect':68 'encount':40 'expand':59 'fail':36 'file':66 'file-type-detect':65 'find':38 'focus':57 'importerror':35 'instal':12 'libmag':17,25,39,44,69 'librari':19,27 'lightweight':5 'like':46 'magic':49 'packag':7 'pre':23 'pre-compil':22 'primarili':31 'provid':21 'pylibmag':1,2 'python':6,29,48,60 'python-mag':47 'releas':56 'share':26 'simplifi':10 'support':64 'type':67 'usag':14 'use':42 'version':52,61 'via':28 'wheel':30,74","created_at":"2026-04-16T17:02:28.988459+00:00","updated_at":"2026-04-16T17:02:28.988459+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nImportError: cannot import name 'magic' from 'pylibmagic' (/tmp/tmp8ls7klkn/venv/lib/python3.12/site-packages/pylibmagic/__init__.py)"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.5.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/kratsg/pylibmagic","docs":"https://pylibmagic.readthedocs.io/","changelog":"https://github.com/kratsg/pylibmagic/releases","pypi":"https://pypi.org/project/pylibmagic/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}