Which jep
version should be used for 0.3.0+17-2bfe86de
? I tried both 3.8.2
and 3.9.0
and both result in following error:
[error] Native library (darwin/libpython3.7m.dylib) not found in resource path (/var/folders/lr/x_gb25v56fj3_80kyyk17lhc0000gn/T/sbt_dd5aa2c1/job-2/target/90ed79f3/562ee7c8/scala-python-example_2.12-1.0.jar:/var/folders/lr/x_gb25v56fj3_80kyyk17lhc0000gn/T/sbt_dd5aa2c1/target/567bf6c2/9e2a823f/jep-3.9.0.jar:/var/folders/lr/x_gb25v56fj3_80kyyk17lhc0000gn/T/sbt_dd5aa2c1/target/bc8bc145/464fe2e1/scala-library.jar:/var/folders/lr/x_gb25v56fj3_80kyyk17lhc0000gn/T/sbt_dd5aa2c1/target/aa0ecde6/28d0208b/scalapy-macros_2.12-0.3.0%2B17-2bfe86de.jar:/var/folders/lr/x_gb25v56fj3_80kyyk17lhc0000gn/T/sbt_dd5aa2c1/target/1a583173/abb78bc4/jna-5.4.0.jar:/var/folders/lr/x_gb25v56fj3_80kyyk17lhc0000gn/T/sbt_dd5aa2c1/target/26ba9c6e/34d55877/scalapy-core_2.12-0.3.0%2B17-2bfe86de.jar:/var/folders/lr/x_gb25v56fj3_80kyyk17lhc0000gn/T/sbt_dd5aa2c1/target/2ce76994/5a36165d/scala-reflect.jar)
[error] at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:302)
[error] at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:455)
[error] at com.sun.jna.Native.register(Native.java:1722)
[error] at com.sun.jna.Native.register(Native.java:1443)
[error] at me.shadaj.scalapy.py.CPythonAPIInterface.<init>(CPythonAPI.scala:6)
[error] at me.shadaj.scalapy.py.CPythonAPI$.<init>(CPythonAPI.scala:74)
[error] at me.shadaj.scalapy.py.CPythonAPI$.<clinit>(CPythonAPI.scala)
[error] at me.shadaj.scalapy.py.CPythonInterpreter$.<init>(CPythonInterpreter.scala:4)
[error] at me.shadaj.scalapy.py.CPythonInterpreter$.<clinit>(CPythonInterpreter.scala)
[error] at me.shadaj.scalapy.py.package$.<init>(package.scala:12)
[error] at me.shadaj.scalapy.py.package$.<clinit>(package.scala)
[error] at com.sushant.example.PiotrekExample$.delayedEndpoint$com$sushant$example$PiotrekExample$1(PiotrekExample.scala:13)
[error] at com.sushant.example.PiotrekExample$delayedInit$body.apply(PiotrekExample.scala:8)
[error] at scala.Function0.apply$mcV$sp(Function0.scala:39)
[error] at scala.Function0.apply$mcV$sp$(Function0.scala:39)
[error] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
[error] at scala.App.$anonfun$main$1$adapted(App.scala:80)
[error] at scala.collection.immutable.List.foreach(List.scala:392)
[error] at scala.App.main(App.scala:80)
[error] at scala.App.main$(App.scala:78)
[error] at com.sushant.example.PiotrekExample$.main(PiotrekExample.scala:8)
[error] at com.sushant.example.PiotrekExample.main(PiotrekExample.scala)
[error] Suppressed: java.lang.UnsatisfiedLinkError: dlopen(libpython3.7m.dylib, 9): image not found
[error] at com.sun.jna.Native.open(Native Method)
[error] at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:191)
[error] ... 21 more
The same code works with scalapy 0.3.0. Any idea what could be missing from my setup?
It fails on val tf = py.module("tensorflow")
Is there any example of a class which can be created by the user calling constructor directly? e.g.
@py.native class Conv2D(
filters: Int,
kernel_size: py.|[Int, (Int, Int)],
strides: py.|[Int, (Int, Int)] = (1, 1),
padding: String = "valid",
data_format: String = "channels_last",
dilation_rate: py.|[Int, (Int, Int)] = (1, 1),
activation: Option[String] = None,
use_bias: Boolean = true,
kernel_initializer: String = "glorot_uniform",
bias_initializer: String = "zeros",
kernel_regularizer: Option[String] = None,
bias_regularizer: Option[String] = None,
activity_regularizer: Option[String] = None,
kernel_constraint: Option[String] = None,
bias_constraint: Option[String] = None
) extends py.Object
I would like to be able to call it like Conv2D(32, kernel_size = (3, 3))
but I'm not sure how to provide PyValue
@shadaj Thanks, I will try it. Do you mean something like:
@py.native abstract class MyClass(x: String) extends py.Object
@py.native object MyClass extends py.Object {
def apply(x: String): MyClass = py.native
}
Although I need to provide Reader[MyClass]
and PyValue
for the object itself
I have some classes working if there is a single parameter (val value: PyValue
) but I have trouble to do it if there are more
@Avasil MyClass
would have to be a trait with x
being defined as a method inside. Right now, ScalaPy also doesn't support top-level objects as facades, so you would need to define a separate trait which contains the constructor which gets a bit messy. What I'd suggest is defining the constructor inside the facade for the containing module, similar to how https://github.com/shadaj/scalapy-tensorflow/blob/master/src/main/scala/me/shadaj/scalapy/tensorflow/TensorFlow.scala#L52 defines the constructor for Variable
.
This is not too elegant unfortunately, but improving this is my top priority after stabilizing the new interpreter backend so should improve soon!
scalapy-test:>python3-config --ldflags
-L/Users/brandons/.pyenv/versions/3.8.5/lib/python3.8/config-3.8-darwin -lintl -ldl -framework CoreFoundation
sbt:scalapy-test> run
[info] running (fork) Main
[error] Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'python3':
[error] dlopen(libpython3.dylib, 9): image not found
[error] dlopen(libpython3.dylib, 9): image not found
[error] Native library (darwin/libpython3.dylib) not found in resource path (TOO LONG)
[error] at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:302)
[error] at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:455)
[error] at com.sun.jna.Native.register(Native.java:1722)
[error] at com.sun.jna.Native.register(Native.java:1443)
[error] at me.shadaj.scalapy.interpreter.CPythonAPIInterface.$anonfun$new$2(CPythonAPI.scala:13)
[error] at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
[error] at scala.util.Try$.apply(Try.scala:210)
[error] at me.shadaj.scalapy.interpreter.CPythonAPIInterface.$anonfun$new$1(CPythonAPI.scala:13)
[error] at me.shadaj.scalapy.interpreter.CPythonAPIInterface.$anonfun$new$1$adapted(CPythonAPI.scala:13)
[error] at scala.collection.immutable.List.find(List.scala:413)
[error] at me.shadaj.scalapy.interpreter.CPythonAPIInterface.<init>(CPythonAPI.scala:13)
[error] at me.shadaj.scalapy.interpreter.CPythonAPI$.<init>(CPythonAPI.scala:95)
[error] at me.shadaj.scalapy.interpreter.CPythonAPI$.<clinit>(CPythonAPI.scala:95)
[error] at me.shadaj.scalapy.interpreter.CPythonInterpreter$.<clinit>(CPythonInterpreter.scala:9)
[error] at me.shadaj.scalapy.py.package$.<clinit>(package.scala:15)
[error] at Main$.main(Main.scala:13)
[error] at Main.main(Main.scala)
[error] Suppressed: java.lang.UnsatisfiedLinkError: dlopen(libpython3.dylib, 9): image not found
[error] at com.sun.jna.Native.open(Native Method)
[error] at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:191)
[error] ... 16 more
[error] Suppressed: java.lang.UnsatisfiedLinkError: dlopen(libpython3.dylib, 9): image not found
[error] at com.sun.jna.Native.open(Native Method)
[error] at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:204)
[error] ... 16 more
[error] Suppressed: java.io.IOException: Native library (darwin/libpython3.dylib) not found in resource path (TOO LONG)
[error] at com.sun.jna.Native.extractFromResourcePath(Native.java:1095)
[error] at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:276)
[error] ... 16 more
[error] Nonzero exit code returned from runner: 1
[error] (Compile / run) Nonzero exit code returned from runner: 1
[error] Total time: 1 s, completed Nov 24, 2020 2:04:42 PM
sbt:scalapy-test>
ThisBuild / scalaVersion := "2.13.3"
libraryDependencies += "me.shadaj" %% "scalapy-core" % "0.4.0"
fork := true
import scala.sys.process._
javaOptions += s"-Djava.library.path=${"python3-config --ldflags".!! + "/lib"}"
-Djna.library.path=/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib
which is effectively -Djna.library.path=${"python3-config --prefix".!!.trim}/lib
SCALAPY_PYTHON_LIBRARY = python3.8
SCALAPY_PYTHON_LIBRARY=python3.6m
(replacing 3.6 with the appropriate Python version) to fix it for now