dify icon indicating copy to clipboard operation
dify copied to clipboard

pip install regex resulting in ImportError: libpthread.so.0: cannot open shared object file: No such file or directory

Open pyxsqbs opened this issue 1 year ago • 4 comments

Self Checks

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

Dify version

0.7.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I just want to try import the regex package because there are always problems with import the python package with dify. TOT image Dify-api version is 0.7.1 and dify-sandbox version is 0.2.6.

code snippet:

import regex
def main() -> dict:
    return {
        "result": "",
    }

Click to run and the following error appears: image

error snippet:

Traceback (most recent call last): File "/var/sandbox/sandbox-python/tmp/2e9531ad_be8f_45b5_b8f8_7827bc32f797.py", line 48, in <module> File "<string>", line 3, in <module> File "/usr/local/lib/python3.10/site-packages/regex/__init__.py", line 1, in <module> from .regex import * File "/usr/local/lib/python3.10/site-packages/regex/regex.py", line 417, in <module> import regex._regex_core as _regex_core File "/usr/local/lib/python3.10/site-packages/regex/_regex_core.py", line 21, in <module> import regex._regex as _regex ImportError: libpthread.so.0: cannot open shared object file: No such file or directory error: exit status 255

✔️ Expected Behavior

Run success!

❌ Actual Behavior

ImportError: libpthread.so.0: cannot open shared object file: No such file or directory

pyxsqbs avatar Aug 20 '24 09:08 pyxsqbs

@pyxsqbs Hello there! I'm here to help you with any bugs, questions, or contributions.

To resolve the ImportError: libpthread.so.0: cannot open shared object file when trying to import the regex package in a self-hosted Dify environment, you need to ensure that the necessary shared libraries are installed on your system. This error typically indicates that the libpthread library, which is part of the GNU C Library (glibc), is missing or not properly linked.

Here are the steps to resolve this issue:

  1. Install the necessary libraries: On a Linux system, you can install the required libraries using your package manager. For example, on Debian-based systems (like Ubuntu), you can use apt-get:

    sudo apt-get update
    sudo apt-get install libc6
    

    On Red Hat-based systems (like CentOS), you can use yum:

    sudo yum install glibc
    
  2. Verify the installation: Ensure that the libpthread.so.0 file exists in your system's library path. You can check this by running:

    ls /lib/x86_64-linux-gnu/libpthread.so.0
    

    or

    ls /usr/lib64/libpthread.so.0
    

    If the file exists, it should be properly linked.

  3. Dockerfile Adjustments: If you are using Docker to host your Dify environment, ensure that your Dockerfile includes the necessary libraries. Based on the provided Dockerfile for Dify, you should already have the required libraries installed. However, you can double-check and add the following lines if they are missing:

    RUN apt-get update \
        && apt-get install -y --no-install-recommends libc6
    
  4. Restart your environment: After installing the necessary libraries, restart your Python environment and try importing the regex package again.

If you follow these steps, the ImportError should be resolved, and you should be able to import the regex package without issues [1][2].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Aug 20 '24 09:08 dosubot[bot]

If you would like to add third-party libs, you need to add things here first.

https://github.com/langgenius/dify/blob/bbef964eb5caaca6df74b21a596900f31faff677/docker/volumes/sandbox/dependencies/python-requirements.txt

And sandbox is a system wrapper for executing codes, which means it needs some native libs like your case, so make sure you can run this code in the sandbox container.

See FAQ 1 here.

var DEFAULT_PYTHON_LIB_REQUIREMENTS = []string{
    "/usr/local/lib/python3.10", // Usually your Python installation directory; if using conda, modify this to the conda virtual environment root directory, e.g., /root/anaconda3/envs/{env_name}
    "/usr/lib/python3.10",
    "/usr/lib/python3",
    "/usr/lib/x86_64-linux-gnu/libssl.so.3", // Your Python code's shared object dependency; it will be copied to /var/sandbox/sandbox-python/usr/lib/x86_64-linux-gnu/, and your Python process will load it from /usr/lib/x86_64-linux-gnu/
    "/usr/lib/x86_64-linux-gnu/libcrypto.so.3", // Similar to above
    "/etc/ssl/certs/ca-certificates.crt",
    "/etc/nsswitch.conf",
    "/etc/hosts",
    "/etc/resolv.conf",
    "/run/systemd/resolve/stub-resolv.conf",
    "/run/resolvconf/resolv.conf",
}

https://github.com/langgenius/dify-sandbox/blob/main/FAQ.md

crazywoola avatar Aug 20 '24 09:08 crazywoola

@Yeuoly Could you kindly review this, please?

pyxsqbs avatar Aug 20 '24 09:08 pyxsqbs

@Yeuoly Could you kindly review this, please?

Are you interested in contributing this? Just add libpthread.so.0 into DEFAULT_PYTHON_LIB_REQUIREMENTS and do some tests for it.

Yeuoly avatar Aug 20 '24 09:08 Yeuoly