Kotlin / kotlin-numpy

Kotlin bindings for NumPy
Apache License 2.0
316 stars 11 forks source link

Can't load Python on Mac #3

Closed alannnna closed 4 years ago

alannnna commented 4 years ago

When running the example code from the readme, I get the following error:

java.io.FileNotFoundException: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/Python.framework/Versions/3.7/Python
    at org.jetbrains.numkt.LibraryLoader.loadLibraries(NativeLibUtils.kt:74)
    at org.jetbrains.numkt.Interpreter.initialize(Interpreter.kt:49)
    at org.jetbrains.numkt.Interpreter.access$initialize(Interpreter.kt:24)
    at org.jetbrains.numkt.Interpreter$Companion.getInterpreter(Interpreter.kt:31)
    at org.jetbrains.numkt.UtilsKt.callFunc(Utils.kt:38)
    at org.jetbrains.numkt.UtilsKt.callFunc$default(Utils.kt:36)
    at numkt2.AppTest.runNumpyStuff(AppTest.kt:47)
        ...

The path it is looking for does not exist on my system: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/Python.framework/Versions/3.7/Python

The values of LIBDIR and LDLIBRARY are as follows:

In [13]: sysconfig.get_config_var('LIBDIR')
Out[13]: '/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib'

In [14]: sysconfig.get_config_var('LDLIBRARY')
Out[14]: 'Python.framework/Versions/3.7/Python'

Edit: I do have a libpython3.7.dylib on my system at /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib, but there appear to be no sysconfig variables pointing at it.

devcrocod commented 4 years ago

Originally used Python from Anaconda. For Anaconda6 the value of LDLIBRARY is the name of Python native library (e.g. libpython3.7m.dylib).

Through sysconfig, we can get LIBDIR and then get the correct version through LDVERSION. There can be two versions in the lib directory with or without pymalloc.

alannnna commented 4 years ago

Thank you for the quick fix!