I’m still learning Elixir,and am making a basic elixir program to call a function from a python program. I am attempting to use erlport to do so. However, in the code below Erlport is undefined. I don’t see what could be causing it.
defmodule RarFile do
@moduledoc """
Documentation for `RarFile`.
"""
@doc """
Hello world.
## Examples
iex> RarFile.hello()
:world
"""
def extractor(filepath) do
{:ok, pid} = :erlport.open_port({:spawn, "python"}, [:binary, :stream, packet: 4])
end
end
Here is the mix.exs file that I’m using.
defmodule RarFile.MixProject do
use Mix.Project
def project do
[
app: :rar_file,
version: "0.1.0",
elixir: "~> 1.14",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:erlport, "~> 0.10"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
hi @Tormenator1 please always include a copy and paste of the exact error when asking about an error.
In glancing at the docs found here ErlPort - Python documentation the function you are trying to use is never mentioned, are you sure you’re calling a function that exists?
No need to use charlist here, You can use binaries…
But it is only half of the problem, because the Python part is tricky to setup. You’ll need to do some conversion of data in the Python script. Something like this…
if isinstance(path, bytes):
path = path.decode("utf-8")
if not os.path.exists(path):
return ("error", "path does not exists.")
else:
return ("error", "cannot decode path.")