Kotlin/kotlin-numpy

Can't load Python on Mac

alannnna opened this issue · 2 comments

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.

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.

Thank you for the quick fix!