goplus / llgo

A Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python
Apache License 2.0
323 stars 26 forks source link

llgo run _pydemo got error by other way install python #344

Open luoliwoshang opened 3 months ago

luoliwoshang commented 3 months ago

We need to prompt the user to set DYLD_LIBRARY_PATH


I configured the python environment through conda, and I have set the LLGO_LIB_PYTHON

❯ echo $LLGO_LIB_PYTHON      
/opt/anaconda3/envs/python312env/lib/python3.12
(python312env) 
❯ llgo run .
dyld[64794]: Library not loaded: @rpath/libpython3.12.dylib
  Referenced from: <3A4ABF35-C399-30BF-A363-274C7529E109> /Users/zhangzhiyang/go/bin/callpy
  Reason: tried: '/libpython3.12.dylib' (no such file)

When 'DYLD_LIBRARY_PATH' is set, it will run normally

export DYLD_LIBRARY_PATH=/opt/anaconda3/envs/python312env/lib:$DYLD_LIBRARY_PATH

Environment

mac version: MacOS 14.2 M3 MacBook Pro (2023)

uname -a
Darwin ... 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:54:55 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8122 arm64
clang -v 
Homebrew clang version 17.0.6
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm@17/bin
go version      
go version go1.20.14 darwin/arm64

python version

❯ which python                           
/opt/anaconda3/envs/python312env/bin/python

❯ python --version
Python 3.12.3
(python312env) 
aofei commented 3 months ago

I configured the python environment through conda, and I have set the LLGO_LIB_PYTHON

❯ echo $LLGO_LIB_PYTHON      
/opt/anaconda3/envs/python312env/lib/python3.12
(python312env) 
❯ llgo run .
dyld[64794]: Library not loaded: @rpath/libpython3.12.dylib
  Referenced from: <3A4ABF35-C399-30BF-A363-274C7529E109> /Users/zhangzhiyang/go/bin/callpy
  Reason: tried: '/libpython3.12.dylib' (no such file)

What happens if you set LLGO_LIB_PYTHON to -L/opt/anaconda3/envs/python312env/lib -lpython3.12?

luoliwoshang commented 3 months ago

I configured the python environment through conda, and I have set the LLGO_LIB_PYTHON我通过 conda 配置了 python 环境,并且设置了 LLGO_LIB_PYTHON

❯ echo $LLGO_LIB_PYTHON      
/opt/anaconda3/envs/python312env/lib/python3.12
(python312env) 
❯ llgo run .
dyld[64794]: Library not loaded: @rpath/libpython3.12.dylib
  Referenced from: <3A4ABF35-C399-30BF-A363-274C7529E109> /Users/zhangzhiyang/go/bin/callpy
  Reason: tried: '/libpython3.12.dylib' (no such file)

What happens if you set LLGO_LIB_PYTHON to -L/opt/anaconda3/envs/python312env/lib -lpython3.12?如果设置为 LLGO_LIB_PYTHON -L/opt/anaconda3/envs/python312env/lib -lpython3.12

It's still the same.

❯ echo $LLGO_LIB_PYTHON                                                       
-L/opt/anaconda3/envs/python312env/lib -lpython3.12
(base) 
llgo/_pydemo/callpy on  main [$?] via 🐹 v1.20.13 
❯ llgo run .                                                                  
dyld[35298]: Library not loaded: @rpath/libpython3.12.dylib
  Referenced from: <CC44AA19-ED3D-33F8-816A-EB8B12E903AF> /Users/zhangzhiyang/go/bin/callpy
  Reason: tried: '/libpython3.12.dylib' (no such file)