以下のでElixirからPythonのプログラムを呼び出す方法について質問してそれに関してはお陰様で解決いたしました。
https://teratail.com/questions/114967
しかし今回別のプログラムで、ElixirからPythonを呼び、そのPython側でファイルを読みむ作業をしたところその読み込みたいファイルが無いといったエラーが出ました。
pyexというディレクトリにmix.exsや、libというディレクトリがあります。そのlibの中にPythonを呼び出すためのpyex.exがありさらにpy_test.pyという今回Elixirから呼び出したいPythonプログラム、そしてpy_test.pyから呼び出す150trainig_sというテキストファイルがあります。pyex.exに関しては以下のようにしてあります。
Elixir
1defmodule Pyex do 2 def test() do 3 { :ok, py_exec } = :python.start( [ python: '/usr/local/bin/python3', python_path: 'lib' ] ) 4 :python.call( py_exec, :py_test, :test, [] ) 5 :python.stop( py_exec ) 6 end 7end 8
これをpyexからiex -S mixで呼び出し、iex(1)> Pyex.test() で実行すると、以下のようなエラーが出ます。
** (ErlangError) Erlang error: {:python, :"builtins.FileNotFoundError", '[Errno 2] No such file or directory: '150trainig_s'', {:"$erlport.opaque", :python, <<128, 2, 99, 116, 114, 97, 99, 101, 98, 97, 99, 107, 10, 83, 116, 97, 99, 107, 83, 117, 109, 109, 97, 114, 121, 10, 113, 0, 41, 129, 113, 1, 40, 99, 116, 114, 97, 99, 101, 98, 97, 99, 107, ...>>}}
(erlport) /Users/tmsmac/pyex/deps/erlport/src/erlport.erl:234: :erlport.call/3
(pyex) lib/pyex.ex:33: Pyex.test/0
No such file or directory: '150trainig_s\ということなので150trainig_sが無いということなんだと思いますが、150trainig_sはpy_test.pyと同じディレクトリ内にあります。またlibから直接Puthon3 py_test.pyで実行すると普通に動きます。Elixirから呼び出す際はまたさらに別のパスの設定などが必要なのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。