在虚拟环境中设置clj-python时遇到以下错误。
为了解决该错误,我做了两个步骤,但错误仍然存在。
使用“ py /初始化!”来指定“ :python-executable ”和“ :library-path ”(请参阅来源“ core.clj:
如果我在virtualenv的lib“〜/ .venv / ml / lib / libpython3.7m.dylib”目录中进行了符号链接,则无法启动“ lein repl”。
例如ln -s /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib
请随时发表评论。
2020年5月24日更新
将本地字典中的“:python-executable” 和“:python-executable” 撤消时,可以启动“ lein repl” 。
(ns my-stuff.core
(:require [libpython-clj.python :as py]))
(py/initialize! :python-executable "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/bin/python3.7"
:library-path "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib")
(require '[libpython-clj.require :refer [require-python]])
错误
my-stuff.core=> May 23, 2020 6:39:35 PM clojure.tools.logging$eval505$fn__508 invoke
INFO: Executing python initialize with options:{:python-executable "/Users/nelson/.venv/ml/bin/python", :program-name nil, :python-home nil, :library-path "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"}
May 23, 2020 6:39:35 PM clojure.tools.logging$eval505$fn__508 invoke
INFO: Detecting startup-info for Python executable: /Users/nelson/.venv/ml/bin/python
May 23, 2020 6:39:35 PM clojure.tools.logging$eval505$fn__508 invoke
INFO: Startup info detected:
{:lib-version "3.7",
:java-library-path-addendum "/Users/nelson/.venv/ml/lib",
:exec-prefix "/Users/nelson/.venv/ml",
:executable "/Users/nelson/.venv/ml/bin/python",
:libnames
("/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"
"python3.7"),
:prefix "/Users/nelson/.venv/ml",
:base-prefix
"/usr/local/opt/python/bin/../Frameworks/Python.framework/Versions/3.7",
:base-exec-prefix
"/usr/local/opt/python/bin/../Frameworks/Python.framework/Versions/3.7",
:python-home "/Users/nelson/.venv/ml",
:version [3 7 7],
:platform "darwin"}
May 23, 2020 6:39:35 PM clojure.tools.logging$eval505$fn__508 invoke
INFO: Trying python library names ["/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib" "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib" "python3.7" "python3.7m" "python3.6m"]
May 23, 2020 6:39:35 PM clojure.tools.logging$eval505$fn__508 invoke
INFO: Setting java library path: /Users/nelson/.venv/ml/lib:/Users/nelson/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
May 23, 2020 6:39:35 PM clojure.tools.logging$eval505$fn__508 invoke
INFO: Reference thread starting
May 23, 2020 6:39:35 PM clojure.tools.logging$eval505$fn__508 invoke
INFO: Library /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib found at [:system "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"]
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x0000700008986000 (most recent call first):
Subprocess failed (exit code: 134)
project.clj
(defproject my-stuff "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.1"]
[clj-python/libpython-clj "1.44"]]
:main ^:skip-aot my-stuff.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
core.clj
(ns my-stuff.core
(:require [libpython-clj.python :as py]
[libpython-clj.jna.base]))
(py/initialize! :python-executable (str (System/getenv "HOME") "/.venv/ml/bin/python")
:library-path (str "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"))
答案 0 :(得分:0)
不久前,我对clj-python进行了一次小测试,并且lein似乎存在局限性,因此鼓励新项目使用clj
工具和deps.edn。
我有一个使用virtualenv的小示例,其中包括Clojure / Python互操作以及一个小型库,您可以在以下虚拟环境中从pip安装:https://github.com/dfuenzalida/clj-python-interop