次のようにPythonのモジュールを作成しJuliaから呼び出すことを考えています。
(ここでは再現可能な最小限のソースリストで,実際には違います)
python
1# MyPyModule.py 2 3 4def greeting() -> None: 5 print("Hello World!")
pythonのモジュールと同じフォルダに次のように実装しました。
julia
1# test_pymodule.jl 2using PyCall 3 4const mymodule = pyimport("MyPyModule") 5mymodule.greeting()
ソースのあるフォルダをカレントディレクトリとして
Repl上から実行させると次のようなエラーが出ます。
julia> include("test_pymodule.jl") ERROR: LoadError: PyError (PyImport_ImportModule The Python package MyPyModule could not be imported by pyimport. Usually this means that you did not install MyPyModule in the Python version being used by PyCall. PyCall is currently configured to use the Julia-specific Python distribution installed by the Conda.jl package. To install the MyPyModule module, you can use `pyimport_conda("MyPyModule", PKG)`, where PKG is the Anaconda package that contains the module MyPyModule, or alternatively you can use the Conda package directly (via `using Conda` followed by `Conda.add` etcetera). Alternatively, if you want to use a different Python distribution on your system, such as a system-wide Python (as opposed to the Julia-specific Python), you can re-configure PyCall with that Python. As explained in the PyCall documentation, set ENV["PYTHON"] to the path/name of the python executable you want to use, run Pkg.build("PyCall"), and re-launch Julia. ) <class 'ModuleNotFoundError'> ModuleNotFoundError("No module named 'MyPyModule'") Stacktrace: [1] pyimport(name::String) @ PyCall ~/.julia/packages/PyCall/ygXW2/src/PyCall.jl:558 [2] top-level scope @ ~/test/test_pymodule.jl:9 [3] include(fname::String) @ Base.MainInclude ./client.jl:476 [4] top-level scope @ REPL[3]:1 in expression starting at /home/ujimushi/test/test_pymodule.jl:9
どのようにしたらうまく呼び出せるでしょうか?
- Julia 1.8.3
- PyCall 1.94.1

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。