SCALAPY_PYTHON_LIBRARY=python3.6m
(replacing 3.6 with the appropriate Python version) to fix it for now
Hello all, the folowing snippet fails to compile:
import me.shadaj.scalapy.numpy.NumPy
import me.shadaj.scalapy.py
val np = py.module("numpy").as[NumPy]
could not find implicit value for evidence parameter of type me.shadaj.scalapy.readwrite.Reader[me.shadaj.scalapy.numpy.NumPy]
val np = py.module("numpy").as[NumPy]
Any hints?
py.module("numpy")
compiles despite missing implicit jep: Jep
, whereas implicitly[Jep]
fails to compile.
Hi! I was following the Getting Started https://scalapy.dev/docs/ instructions, but when I tried running the code example, I got:
[error] Exception in thread "main" java.lang.ExceptionInInitializerError
[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$package$.hello(Main.scala:5)
[error] at hello.main(Main.scala:4)
[error] Caused by: java.lang.Exception: Unable to locate Python library, tried python3, python3.7, python3.7m
[error] at me.shadaj.scalapy.interpreter.CPythonAPIInterface.$anonfun$new$2(CPythonAPI.scala:19)
[error] at scala.Option.getOrElse(Option.scala:201)
[error] at me.shadaj.scalapy.interpreter.CPythonAPIInterface.<init>(CPythonAPI.scala:19)
[error] at me.shadaj.scalapy.interpreter.CPythonAPI$.<init>(CPythonAPI.scala:102)
[error] at me.shadaj.scalapy.interpreter.CPythonAPI$.<clinit>(CPythonAPI.scala:102)
[error] ... 4 more
Python was installed via homebrew, the OS is MacOS Catalina. The output of python3-config --configdir
is /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/config-3.9-darwin
. When I run ls -1 $(python3-config --configdir)
, I get:
Makefile
Setup
Setup.local
config.c
config.c.in
install-sh
libpython3.9.a
libpython3.9.dylib
makesetup
python-config.py
python.o
So probably javaOptions += s"-Djava.library.path=${"python3-config --configdir".!!.trim}/lib"
in the SBT settings cannot locate lib
. How do I fix this?
Hello, I am trying to see how ScalaPy works through a simple example to visualize a Jupyter widget using the python module of ipywidgets, with the following code:
import $ivy.`me.shadaj::scalapy-core:0.4.2`
import me.shadaj.scalapy.py
import me.shadaj.scalapy.py.SeqConverters
val w = py.module ("ipywidgets")
w: py.Module = <module 'ipywidgets' from '/home/javier/anaconda3/envs/jupyterlab-env/lib/python3.8/site-packages/ipywidgets/__init__.py'>
val dsp = py.module("IPython.display")
dsp: py.Module = <module 'IPython.display' from '/home/javier/anaconda3/envs/jupyterlab-env/lib/python3.8/site-packages/IPython/display.py'>
val w1 = w.IntSlider(10)
w1: py.Dynamic = IntSlider(value=10)
dsp.display(w1.toPythonProxy)
But I don't know how to pass the reference of the python IntSlider object to the python display function. I have tried with the toPythonProxy function but it is not defined for the IntSlider widget object and it produces an error:
me.shadaj.scalapy.py.PythonException: <class 'AttributeError'> 'IntSlider' object has no attribute 'toPythonProxy'
me.shadaj.scalapy.interpreter.CPythonInterpreter$.$anonfun$throwErrorIfOccured$1(CPythonInterpreter.scala:315)
me.shadaj.scalapy.interpreter.Platform$.Zone(Platform.scala:10)
me.shadaj.scalapy.interpreter.CPythonInterpreter$.throwErrorIfOccured(CPythonInterpreter.scala:301)
me.shadaj.scalapy.interpreter.CPythonInterpreter$.$anonfun$select$1(CPythonInterpreter.scala:501)
me.shadaj.scalapy.interpreter.CPythonInterpreter$.withGil(CPythonInterpreter.scala:148)
me.shadaj.scalapy.interpreter.CPythonInterpreter$.select(CPythonInterpreter.scala:493)
me.shadaj.scalapy.py.AnyDynamics.selectDynamic(Dynamic.scala:43)
me.shadaj.scalapy.py.AnyDynamics.selectDynamic$(Dynamic.scala:42)
me.shadaj.scalapy.py.AnyDynamics$$anon$7$$anon$8.selectDynamic(Dynamic.scala:31)
ammonite.$sess.cmd9$Helper.<init>(cmd9.sc:1)
ammonite.$sess.cmd9$.<clinit>(cmd9.sc:7)
How could I pass the IntSlider (py.Dynamic) object to the python display function?
dsp.display(w1)
prints out: res11: py.Dynamic = None
toPythonProxy
and toPythonCopy
only need to be used when passing Scala sequences into Python code (an explicit conversion is required because these operations can be fairly costly on the JVM).
python3
fail to load, since ScalaPy has logic (in 0.4.2) to fall back to other Python versions (https://github.com/shadaj/scalapy/blob/master/core/jvm/src/main/scala/me/shadaj/scalapy/interpreter/CPythonAPI.scala#L10). Can you ensure that you're on the latest version? This behavior used to be buggy in previous versions.
Hi @cedricmjohn,
It seems to me that I had a similar problem to yours (during running the scalaPy in intellij), and in my case, it was solved in the next way:
1. firstly run python3-config --ldflags
You maybe will see something like this: -L/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/config-3.9-darwin -ldl -framework CoreFoundation
and check if the libpython3.9.dylib exists
Maybe it will be helpful
brew install python3
to install python. Maybe you can try to install python with homebrew but it will possibly have conflicts with anaconda's python (I am not completely sure in i), so maybe it is better to uninstall it before installing python with homebrew
@ekrich @jlareckm_twitter and @shadaj:matrix.org : I figured it out! @jlareckm_twitter your thread was a great help, thanks a lot! I found out thanks to your image where to change the VM options and even where to put the environmental variable, and it worked in my IntelliJ version! Thanks a ton!!!
@shadaj:matrix.org and anyone out there with an Anaconda install: it might be just me, but the 'python3-config --ldflags' approach does not point to the right folder on the latest version of Anaconda Python on a Mac. It does point to the correct Python version in the Darwin folder, but this contains what I think is a symbolic link to the library (libpython3.8.a). It does not work with Scalapy. The trick that worked for me was to redict the path manually as a VM option straight to '/Applications/anaconda3/lib' where the correct 'libpython3.8.dylib' exists.
Is it me and my particular Python install, or does anyone else have this issue too? And I hate to ask it, but how do I set this up on Almond, which was my initial idea?
Thanks and sorry for being a Gitter pain! :)
So, I am playing around on Almond with Scala 13.5 and Python 3.8. I encountered an issue with matplotlib. I first do this import:
val plt = py.module("matplotlib.pyplot")
The I execute:
plt.scatter(Seq(1,2,3).toPythonProxy, Seq(1,2,3).toPythonProxy)
But my JVM crashes and I get this error:
"Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!"
Anyone else has this issue? Can we not use libraries with GUI outputs, or maybe we need to do something in addition to that?
Module
in parallel. My module uses CPython libraries like pandas and NumPy. I was reusing the module instance and using the applyDynamic
method in each iteration. I noticed that there are over 10,000 files opened by the process. Is it expected behavior?