clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.06k stars 69 forks source link

Execution error (ExceptionInfo) at tech.jna.base/do-load-library #123

Closed cocodrino closed 3 years ago

cocodrino commented 3 years ago

Hi good day, I'm having some troubles trying to test libpython-clj, I'm not sure if I'm following the right steps

I found this related issue https://github.com/clj-python/libpython-clj/issues/61, so I installed python with the enable framework parameter activated: 1) env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.6.9 2) I downloaded an installed libpython-clj using lein install 3) I run this code in the repl (cursive)

(ns main
  (:require [libpython-clj.python :as py]
            [clojure.string :as str]))

(py/initialize! :python-executable " /Users/Admin/.pyenv/versions/3.6.9")

this is the output

(py/initialize! :python-executable " /Users/Admin/.pyenv/versions/3.6.9")
sep. 19, 2020 7:56:35 P.M. clojure.tools.logging$eval1774$fn__1777 invoke
INFO: Executing python initialize with options:{:python-executable " /Users/Admin/.pyenv/versions/3.6.9", :program-name nil, :python-home nil, :library-path nil}
sep. 19, 2020 7:56:35 P.M. clojure.tools.logging$eval1774$fn__1777 invoke
INFO: Detecting startup-info for Python executable:  /Users/Admin/.pyenv/versions/3.6.9
sep. 19, 2020 7:56:35 P.M. clojure.tools.logging$eval1774$fn__1777 invoke
INFO: Startup info detected:
{:lib-version "3.8",
 :java-library-path-addendum "/Users/Admin/.pyenv/versions/3.8.1/lib",
 :exec-prefix "/Users/Admin/.pyenv/versions/3.8.1",
 :executable "/Users/Admin/.pyenv/versions/3.8.1/bin/python3",
 :libnames ("python3.8m" "python3.8"),
 :prefix "/Users/Admin/.pyenv/versions/3.8.1",
 :base-prefix "/Users/Admin/.pyenv/versions/3.8.1",
 :base-exec-prefix "/Users/Admin/.pyenv/versions/3.8.1",
 :python-home "/Users/Admin/.pyenv/versions/3.8.1",
 :version [3 8 1],
 :platform "darwin"}

sep. 19, 2020 7:56:35 P.M. clojure.tools.logging$eval1774$fn__1777 invoke
INFO: Trying python library names ["python3.8m" "python3.8" "python3.7m" "python3.6m"]
sep. 19, 2020 7:56:35 P.M. clojure.tools.logging$eval1774$fn__1777 invoke
INFO: Setting java library path: /Users/Admin/.pyenv/versions/3.8.1/lib:/Users/Admin/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
sep. 19, 2020 7:56:35 P.M. clojure.tools.logging$eval1774$fn__1777 invoke
INFO: Reference thread starting
Execution error (ExceptionInfo) at tech.jna.base/do-load-library (base.clj:158).
Failed to load library

notice how the python version differ, I don't know why it's taking another python version

I run

pyenv global 3.6.9
pyenv local 3.6.9
pyenv version
=>3.6.9 (set by /Users/Admin/Downloads/proj/clojure/prueba2a/.python-version)

I also try

(py/initialize! :python-executable " /Users/Admin/.pyenv/versions/3.6.9/bin")
(py/initialize! :python-executable " /Users/Admin/.pyenv/versions/3.6.9/bin/python3")
(py/initialize! :python-executable " /Users/Admin/.pyenv/versions/3.6.9/bin/python")

I always get the same output

do you know what I'm doing wrong?

thank you so much...

Best regards

sogaiu commented 3 years ago

Just to confirm, this is macos, right?

May be one of the following might help:

Haven't tested either on macos though.

cocodrino commented 3 years ago

@sogaiu thank you, :library-path did the trick, would be great if that info could be included in the readme, also notice that python 3.8.1 doesn't work, I get an error when I try to initialize...

thank you so much!

cnuernber commented 3 years ago

Is pyenv active in the shell that you launched your cursive repl in? Could the pyenv shell state be an part of the issue?

sogaiu commented 3 years ago

@cocodrino Along the lines (I think) of what @cnuernber said, if you launch Cursive from a terminal where pyenv is already appropriately activated, it may be that things will "just work".

I think if one launches an application from the Dock it may not have the same set of environment variables set as that of your pyenv environment.

Algorimatica commented 3 years ago

Encountered a same problem with python 3.8.5, should I downgrade to python 3.7?

(ns my-py-clj.config
  (:require [libpython-clj.python :as py]))

;; When you use conda, it should look like this.
(py/initialize! :python-executable "./venv/bin/python"
                :library-path "./venv/lib/libpython3.8m.dylib")
my-py-clj.config=> (py/initialize! :python-executable "./venv/bin/python"
              #_=>                 :library-path "./venv/lib/libpython3.8m.dylib")
Oct 18, 2020 3:33:09 PM clojure.tools.logging$eval1985$fn__1988 invoke
INFO: Executing python initialize with options:{:python-executable "./venv/bin/python", :program-name nil, :python-home nil, :library-path "./venv/lib/libpython3.8m.dylib"}
Oct 18, 2020 3:33:09 PM clojure.tools.logging$eval1985$fn__1988 invoke
INFO: Detecting startup-info for Python executable: ./venv/bin/python
Oct 18, 2020 3:33:09 PM clojure.tools.logging$eval1985$fn__1988 invoke
INFO: Startup info detected:
{:lib-version "3.8",
 :java-library-path-addendum
 "/Users/Shared/Relocated_Items/Security/eUSB/sync/clojure/projects/libpython-clj-play/venv/lib",
 :exec-prefix
 "/Users/Shared/Relocated_Items/Security/eUSB/sync/clojure/projects/libpython-clj-play/venv",
 :executable
 "/Users/Shared/Relocated_Items/Security/eUSB/sync/clojure/projects/libpython-clj-play/venv/bin/python",
 :libnames ("./venv/lib/libpython3.8m.dylib" "python3.8"),
 :prefix
 "/Users/Shared/Relocated_Items/Security/eUSB/sync/clojure/projects/libpython-clj-play/venv",
 :base-prefix
 "/usr/local/opt/python@3.8/bin/../Frameworks/Python.framework/Versions/3.8",
 :base-exec-prefix
 "/usr/local/opt/python@3.8/bin/../Frameworks/Python.framework/Versions/3.8",
 :python-home
 "/Users/Shared/Relocated_Items/Security/eUSB/sync/clojure/projects/libpython-clj-play/venv",
 :version [3 8 5],
 :platform "darwin"}
Oct 18, 2020 3:33:09 PM clojure.tools.logging$eval1985$fn__1988 invoke
INFO: Trying python library names ["./venv/lib/libpython3.8m.dylib" "./venv/lib/libpython3.8m.dylib" "python3.8" "python3.7m" "python3.6m"]
Oct 18, 2020 3:33:09 PM clojure.tools.logging$eval1985$fn__1988 invoke
INFO: Setting java library path: /Users/Shared/Relocated_Items/Security/eUSB/sync/clojure/projects/libpython-clj-play/venv/lib:/Users/nelson/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Oct 18, 2020 3:33:09 PM clojure.tools.logging$eval1985$fn__1988 invoke
INFO: Reference thread starting
Execution error (ExceptionInfo) at tech.jna.base/do-load-library (base.clj:158).
Failed to load library
sogaiu commented 3 years ago

@Algorimatica I had success with the pyenv + pyenv-virtualenv (via homebrew) combination on macos with python 3.8.6 using @cnuernber's find of: https://github.com/pyenv/pyenv/wiki#how-to-build-cpython-with-framework-support-on-os-x

I adapted the instructions from here: https://github.com/clj-python/libpython-clj/issues/2#issuecomment-687547272

Apart from adapting the specific paths and python modules to install, the main differences were:


IIUC, It looks like you are using macos and venv, is that correct?

The following issue had some discussion that mentioned those two: https://github.com/clj-python/libpython-clj/issues/70 -- though I am not sure whether that combination (venv + macos + libpython-clj) has worked out so well for folks.