ImportError: failed to find libmagic. Check your installation #7928

Closed
opened 2026-02-21 18:23:05 -05:00 by yindo · 4 comments
Owner

Originally created by @racerxdl on GitHub (Jan 29, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Start docker container for dify api using main branch to migrate older version. Crash:

  File "/app/api/app_factory.py", line 25, in create_app
2025-01-29T23:43:54.859501026Z     initialize_extensions(app)
  File "/app/api/app_factory.py", line 87, in initialize_extensions
2025-01-29T23:43:54.859505682Z     ext.init_app(app)
  File "/app/api/extensions/ext_blueprints.py", line 10, in init_app
2025-01-29T23:43:54.859510177Z     from controllers.console import bp as console_app_bp
2025-01-29T23:43:54.859512599Z   File "/app/api/controllers/console/__init__.py", line 26, in <module>
2025-01-29T23:43:54.859514827Z     from .remote_files import RemoteFileInfoApi, RemoteFileUploadApi
  File "/app/api/controllers/console/remote_files.py", line 9, in <module>
2025-01-29T23:43:54.859519556Z     from controllers.common import helpers
2025-01-29T23:43:54.859521876Z   File "/app/api/controllers/common/helpers.py", line 10, in <module>
    import magic
2025-01-29T23:43:54.859526397Z   File "/app/api/.venv/lib/python3.12/site-packages/magic/__init__.py", line 209, in <module>
    libmagic = loader.load_lib()
2025-01-29T23:43:54.859531027Z                ^^^^^^^^^^^^^^^^^
2025-01-29T23:43:54.859533276Z   File "/app/api/.venv/lib/python3.12/site-packages/magic/loader.py", line 49, in load_lib
2025-01-29T23:43:54.859535577Z     raise ImportError('failed to find libmagic.  Check your installation')
2025-01-29T23:43:54.859537887Z ImportError: failed to find libmagic.  Check your installation

Seens like missing dependency on docker file.

✔️ Expected Behavior

Works

Actual Behavior

Crash with missing libmagic

  File "/app/api/app_factory.py", line 25, in create_app
2025-01-29T23:43:54.859501026Z     initialize_extensions(app)
  File "/app/api/app_factory.py", line 87, in initialize_extensions
2025-01-29T23:43:54.859505682Z     ext.init_app(app)
  File "/app/api/extensions/ext_blueprints.py", line 10, in init_app
2025-01-29T23:43:54.859510177Z     from controllers.console import bp as console_app_bp
2025-01-29T23:43:54.859512599Z   File "/app/api/controllers/console/__init__.py", line 26, in <module>
2025-01-29T23:43:54.859514827Z     from .remote_files import RemoteFileInfoApi, RemoteFileUploadApi
  File "/app/api/controllers/console/remote_files.py", line 9, in <module>
2025-01-29T23:43:54.859519556Z     from controllers.common import helpers
2025-01-29T23:43:54.859521876Z   File "/app/api/controllers/common/helpers.py", line 10, in <module>
    import magic
2025-01-29T23:43:54.859526397Z   File "/app/api/.venv/lib/python3.12/site-packages/magic/__init__.py", line 209, in <module>
    libmagic = loader.load_lib()
2025-01-29T23:43:54.859531027Z                ^^^^^^^^^^^^^^^^^
2025-01-29T23:43:54.859533276Z   File "/app/api/.venv/lib/python3.12/site-packages/magic/loader.py", line 49, in load_lib
2025-01-29T23:43:54.859535577Z     raise ImportError('failed to find libmagic.  Check your installation')
2025-01-29T23:43:54.859537887Z ImportError: failed to find libmagic.  Check your installation
Originally created by @racerxdl on GitHub (Jan 29, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Start docker container for dify api using `main` branch to migrate older version. Crash: ``` File "/app/api/app_factory.py", line 25, in create_app 2025-01-29T23:43:54.859501026Z initialize_extensions(app) File "/app/api/app_factory.py", line 87, in initialize_extensions 2025-01-29T23:43:54.859505682Z ext.init_app(app) File "/app/api/extensions/ext_blueprints.py", line 10, in init_app 2025-01-29T23:43:54.859510177Z from controllers.console import bp as console_app_bp 2025-01-29T23:43:54.859512599Z File "/app/api/controllers/console/__init__.py", line 26, in <module> 2025-01-29T23:43:54.859514827Z from .remote_files import RemoteFileInfoApi, RemoteFileUploadApi File "/app/api/controllers/console/remote_files.py", line 9, in <module> 2025-01-29T23:43:54.859519556Z from controllers.common import helpers 2025-01-29T23:43:54.859521876Z File "/app/api/controllers/common/helpers.py", line 10, in <module> import magic 2025-01-29T23:43:54.859526397Z File "/app/api/.venv/lib/python3.12/site-packages/magic/__init__.py", line 209, in <module> libmagic = loader.load_lib() 2025-01-29T23:43:54.859531027Z ^^^^^^^^^^^^^^^^^ 2025-01-29T23:43:54.859533276Z File "/app/api/.venv/lib/python3.12/site-packages/magic/loader.py", line 49, in load_lib 2025-01-29T23:43:54.859535577Z raise ImportError('failed to find libmagic. Check your installation') 2025-01-29T23:43:54.859537887Z ImportError: failed to find libmagic. Check your installation ``` Seens like missing dependency on docker file. ### ✔️ Expected Behavior Works ### ❌ Actual Behavior Crash with missing libmagic ``` File "/app/api/app_factory.py", line 25, in create_app 2025-01-29T23:43:54.859501026Z initialize_extensions(app) File "/app/api/app_factory.py", line 87, in initialize_extensions 2025-01-29T23:43:54.859505682Z ext.init_app(app) File "/app/api/extensions/ext_blueprints.py", line 10, in init_app 2025-01-29T23:43:54.859510177Z from controllers.console import bp as console_app_bp 2025-01-29T23:43:54.859512599Z File "/app/api/controllers/console/__init__.py", line 26, in <module> 2025-01-29T23:43:54.859514827Z from .remote_files import RemoteFileInfoApi, RemoteFileUploadApi File "/app/api/controllers/console/remote_files.py", line 9, in <module> 2025-01-29T23:43:54.859519556Z from controllers.common import helpers 2025-01-29T23:43:54.859521876Z File "/app/api/controllers/common/helpers.py", line 10, in <module> import magic 2025-01-29T23:43:54.859526397Z File "/app/api/.venv/lib/python3.12/site-packages/magic/__init__.py", line 209, in <module> libmagic = loader.load_lib() 2025-01-29T23:43:54.859531027Z ^^^^^^^^^^^^^^^^^ 2025-01-29T23:43:54.859533276Z File "/app/api/.venv/lib/python3.12/site-packages/magic/loader.py", line 49, in load_lib 2025-01-29T23:43:54.859535577Z raise ImportError('failed to find libmagic. Check your installation') 2025-01-29T23:43:54.859537887Z ImportError: failed to find libmagic. Check your installation ```
yindo closed this issue 2026-02-21 18:23:05 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 29, 2025):

To resolve the "ImportError: failed to find libmagic" issue in your Docker setup for the Dify API, you need to ensure that the libmagic system library is installed in your Docker container. You can do this by modifying your Dockerfile to include the installation of libmagic. Here's how you can do it:

  1. Open your Dockerfile for the Dify API.

  2. Add the following line to install libmagic:

    RUN apt-get update && apt-get install -y libmagic1
    
  3. Save the Dockerfile and rebuild your Docker image by running:

    docker build -t your-image-name .
    
  4. Restart your Docker container with the newly built image.

This should resolve the missing libmagic dependency and allow your application to run without crashing.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Jan 29, 2025): <!-- Answer --> To resolve the "ImportError: failed to find libmagic" issue in your Docker setup for the Dify API, you need to ensure that the `libmagic` system library is installed in your Docker container. You can do this by modifying your Dockerfile to include the installation of `libmagic`. Here's how you can do it: 1. Open your Dockerfile for the Dify API. 2. Add the following line to install `libmagic`: ```Dockerfile RUN apt-get update && apt-get install -y libmagic1 ``` 3. Save the Dockerfile and rebuild your Docker image by running: ```bash docker build -t your-image-name . ``` 4. Restart your Docker container with the newly built image. This should resolve the missing `libmagic` dependency and allow your application to run without crashing. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/3fe3b978-fa60-46aa-9fbd-4045b1e9a010?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/3fe3b978-fa60-46aa-9fbd-4045b1e9a010?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/3fe3b978-fa60-46aa-9fbd-4045b1e9a010?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/3fe3b978-fa60-46aa-9fbd-4045b1e9a010?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3fe3b978-fa60-46aa-9fbd-4045b1e9a010?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/3fe3b978-fa60-46aa-9fbd-4045b1e9a010?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Jan 30, 2025):

If you are running with mac & source code, you can run brew install libmagic to resolve this issue. The rest operating systems should be same.

Please report bug with the version number like 0.15.2 instead of Latest main on docker.
Since the main branch use this tag 0.15.2 as well, we do not know if you have made changes to it.

After digging into the pull request history, This is introduced in https://github.com/langgenius/dify/pull/12693.

@crazywoola commented on GitHub (Jan 30, 2025): If you are running with mac & source code, you can run ` brew install libmagic` to resolve this issue. The rest operating systems should be same. Please report bug with the version number like `0.15.2` instead of `Latest main on docker`. Since the main branch use this tag `0.15.2` as well, we do not know if you have made changes to it. After digging into the pull request history, This is introduced in https://github.com/langgenius/dify/pull/12693.
Author
Owner

@laipz8200 commented on GitHub (Jan 30, 2025):

We should add libmagic to the Dockerfile. Are you interested in doing this?

@laipz8200 commented on GitHub (Jan 30, 2025): We should add libmagic to the Dockerfile. Are you interested in doing this?
Author
Owner

@obadakhalili commented on GitHub (Feb 3, 2025):

If you are running with mac & source code, you can run brew install libmagic to resolve this issue.

@crazywoola the docs should be updated to reflect that. I opened a PR with this: https://github.com/langgenius/dify-docs/pull/473

@obadakhalili commented on GitHub (Feb 3, 2025): > If you are running with mac & source code, you can run brew install libmagic to resolve this issue. @crazywoola the docs should be updated to reflect that. I opened a PR with this: https://github.com/langgenius/dify-docs/pull/473
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7928