clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.09k stars 68 forks source link

Cannot run the example in the tutorial in Cider with JDK 17 #231

Closed guojing0 closed 2 years ago

guojing0 commented 2 years ago

I'm following this tutorial in Emacs Cider. However, after executing

(require '[libpython-clj2.python
                 :refer [as-python as-jvm
                         ->python ->jvm
                         get-attr call-attr call-attr-kw
                         get-item initialize!
                         run-simple-string
                         add-module module-dict
                         import-module
                         python-type
                         dir]
                 :as py])

The following outputs

Execution error (IllegalStateException) at XXX.core/eval24681$loading (form-init11518615007973882351.clj:1).
dir already refers to: #'clojure.repl/dir in namespace: XXX.core

XXX.core> (initialize!)
:already-initialized
XXX.core> (run-simple-string "print('hey')")
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:445).
jdk.incubator.foreign.MemoryAddress

This is my Java version:

java 17.0.4.1 2022-08-18 LTS
Java(TM) SE Runtime Environment (build 17.0.4.1+1-LTS-2)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.4.1+1-LTS-2, mixed mode, sharing)
jjtolton commented 2 years ago

Thanks, I think we owe the tutorial an overhaul.

guojing0 commented 2 years ago

@jjtolton Thank you for the answer. Are there other "more modern/updated" or simpler tutorials that I could use to get familiar with the library?

I'm thinking about using it to interact with python-chess library, which is less fancy than other AI/ML examples.

cnuernber commented 2 years ago

Please see readme specifically about JDK-17 support

cnuernber commented 2 years ago

Please see readme specifically about JDK-17 support

guojing0 commented 2 years ago

Saw it. (How) can it also work with lein?

cnuernber commented 2 years ago

(On my phone , not trying to be irritating) - https://www.google.com/search?q=lein+jvm-opts

guojing0 commented 2 years ago

Thank you; I am not very familiar with JVM and all these things, so I googled "lein add modules", will close the ticket now.

cnuernber commented 2 years ago

No worries - the JVM is very complex - lots of depth there.