langgenius / dify-sandbox

A lightweight, fast, and secure code execution environment that supports multiple programming languages
https://docs.dify.ai/development/backend/sandbox
Apache License 2.0
434 stars 97 forks source link

v0.2.3 - Error importing numpy: you should not try to import numpy from its source directory #39

Closed EcoleKeine closed 3 months ago

EcoleKeine commented 3 months ago

Version: 0.2.3

Error: Traceback (most recent call last): File "/var/sandbox/sandbox-python/tmp/817ce9f4_7975_43cd_abcc_587b30c0f333.py", line 48, in File "", line 3, in File "/usr/local/lib/python3.10/site-packages/pandas/init.py", line 19, in raise ImportError( ImportError: Unable to import required dependencies: numpy: Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python interpreter from there. error: exit status 255

Code:

import pandas as pd

def main() -> dict:
    df = pd.DataFrame({
    'x': range(1, 6),
    'y': [1, 4, 2, 5, 3]
})
    return {
        "result": df.plot(),
    }

python-requirements.txt: pandas matplotlib

same error if add numpy to python-requirements.txt: pandas numpy matplotlib

lzzzzzzzzz commented 3 months ago

i chage numpy==1.24.1 (lower version) it work, you may Reduce pandas version and try again

sharptornadoqsh commented 3 months ago

you should add the necessary sys call in https://github.com/langgenius/dify-sandbox/blob/main/internal/static/python_syscall/syscalls_amd64.go

the example in faq about numpy's system call is wrong,i add 0 to 500 syscall number i solved the problem

sharptornadoqsh commented 3 months ago

you should add the necessary sys call in https://github.com/langgenius/dify-sandbox/blob/main/internal/static/python_syscall/syscalls_amd64.go

the example in faq about numpy's system call is wrong,i add 0 to 500 syscall number i solved the problem

and the data type in dify's code does't support df.plot()

EcoleKeine commented 3 months ago

the error caused by: "Original error was: libgcc_s.so.1: cannot open shared object file: No such file or directory" seems to be the first issue mentioned in the FAQ.md.