clj-python / libpython-clj

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

Failed to load library on Windows (:libnames construction) #140

Open momerath42 opened 3 years ago

momerath42 commented 3 years ago

I'm just starting to try to use this amazing project. I'm trying to do everything in windows for project-specific reasons. I could be missing something obvious because I lack experience developing clojure/java/python on windows, but it appears to me that the issue is with https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj/python/interpreter.clj#L86 python-library-regex not actually being used (the one call to it being commented out). I could try hacking it into place and submitting a PR, but I assume there's a good reason it's not currently in there. Please advise!

My bare stub of a project is at https://github.com/momerath42/phil for reproduction's sake. Attached is the debug .edn file, and here is the output at the [power]shell:

PS E:\full melon\phil> clj -X phil.core/-main
2020-12-06T23:19:02.336Z VennstationOne INFO [phil.core:10] - using config file: E:\full melon\phil\config_phil.edn
2020-12-06T23:19:02.373Z VennstationOne INFO [phil.core:27] - Hi, I'm PHIL!
2020-12-06T23:19:02.374Z VennstationOne INFO [phil.core:28] - my current working directory is (maybe): E:\full melon\phil
2020-12-06T23:19:02.374Z VennstationOne INFO [phil.core:29] - I slurped this config: {:listens {:python-executable "c:\\Users\\micha\\anaconda3\\python.exe", :library-path "c:\\Users\\micha\\anaconda3", :windows-anaconda-activate-bat "c:\\Users\\micha\\anaconda3\\condabin\\activate.bat"}}
2020-12-06T23:19:02.376Z VennstationOne INFO [phil.listens:10] - listens/start-listening cfg: {:python-executable "c:\\Users\\micha\\anaconda3\\python.exe", :library-path "c:\\Users\\micha\\anaconda3", :windows-anaconda-activate-bat "c:\\Users\\micha\\anaconda3\\condabin\\activate.bat"}
Dec 06, 2020 3:19:02 PM clojure.tools.logging$eval4632$fn__4635 invoke
INFO: Executing python initialize with options:{:python-executable "c:\\Users\\micha\\anaconda3\\python.exe", :program-name nil, :python-home nil, :library-path "c:\\Users\\micha\\anaconda3"}
Dec 06, 2020 3:19:02 PM clojure.tools.logging$eval4632$fn__4635 invoke
INFO: Detecting startup-info for Python executable: c:\Users\micha\anaconda3\python.exe
Dec 06, 2020 3:19:02 PM clojure.tools.logging$eval4632$fn__4635 invoke
INFO: Startup info detected:
{:lib-version "3.8",
 :java-library-path-addendum "c:\\Users\\micha\\anaconda3\\lib",
 :exec-prefix "c:\\Users\\micha\\anaconda3",
 :executable "c:\\Users\\micha\\anaconda3\\python.exe",
 :libnames ("c:\\Users\\micha\\anaconda3" "python3.8"),
 :prefix "c:\\Users\\micha\\anaconda3",
 :base-prefix "c:\\Users\\micha\\anaconda3",
 :base-exec-prefix "c:\\Users\\micha\\anaconda3",
 :python-home "c:\\Users\\micha\\anaconda3",
 :version [3 8 5],
 :platform "win32"}

Dec 06, 2020 3:19:02 PM clojure.tools.logging$eval4632$fn__4635 invoke
INFO: Trying python library names ["c:\\Users\\micha\\anaconda3" "c:\\Users\\micha\\anaconda3" "python3.8" "python3.7m" "python3.6m"]
Dec 06, 2020 3:19:02 PM clojure.tools.logging$eval4632$fn__4635 invoke
INFO: Setting java library path: c:\Users\micha\anaconda3\lib:C:\Users\micha\scoop\apps\adoptopenjdk-lts-hotspot\current\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Users\micha\scoop\apps\adoptopenjdk-lts-hotspot\current\bin;C:\Users\micha\scoop\shims;C:\Program Files\Oculus\Support\oculus-runtime;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\GTK2-Runtime\bin;C:\Program Files (x86)\ZED SDK\dependencies\freeglut_2.8\x64;C:\Program Files (x86)\ZED SDK\dependencies\glew-1.12.0\x64;C:\Program Files (x86)\ZED SDK\dependencies\opencv_3.1.0\x64\vc14\bin;C:\Program Files (x86)\ZED SDK\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\;C:\Users\micha\AppData\Local\Microsoft\WindowsApps;C:\Users\micha\AppData\Local\GitHubDesktop\bin;C:\Users\micha\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Imaginando\UBRIDGE;C:\Users\micha\AppData\Local\Programs\Microsoft VS Code\bin;.
Dec 06, 2020 3:19:02 PM clojure.tools.logging$eval4632$fn__4635 invoke
INFO: Reference thread starting
Execution error (ExceptionInfo) at tech.v3.jna.base/do-load-library (base.clj:157).
Failed to load library

Full report at:
C:\Users\micha\AppData\Local\Temp\clojure-15358896831604690969.edn

libpython-load-fail-edn.txt

cnuernber commented 3 years ago

It is failing to load python3.8m.dll and python3.8.dll and falling back to 3.6 ... I think.

Where is python3.8.dll on your system?

momerath42 commented 3 years ago

in the root anaconda dir, as I specified for :library-path - but it's named python38.dll (no extra period or m)

momerath42 commented 3 years ago

I figured out that if I run powershell through anaconda navigator, libpython-clj finds the 'system' version of the .dll, so I'm no longer stuck. I still think the way I tried before should theoretically work.

jjtolton commented 3 years ago

Conda is a little tricky but we do have a lot of validation for working pathways. Here is the reference setup, would need to be adapted for windows. There are some Powershell specific tips on Zulip!

cnuernber commented 3 years ago

I think the issue is that we do not have a search mechanism that looks for python38.dll, but only python3.8.dll and python3.8m.dll.

You can specify the library path directly (which is a PITA) or we can figure out a more clever search mechanism that will detect these sorts of differences.