Tormenator1

Tormenator1

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

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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?

kokolegorille

kokolegorille

You are confusing erlport eith Elixir Port, they are not the same…

You should do something like this example…

:python.start([{:python_path, to_charlist(path)}, {:python, 'python3'}])

# and

:python.call(pid, :your_python_script, :your_python_function, [params1, params2])
al2o3cr

al2o3cr

FWIW, open_port is a built-in Erlang function.

Erlport provides wrappers to open ports to Python and Ruby executables, you should use one of those if that’s what you’re looking to do.

Tormenator1

Tormenator1 OP

I have multiple python environments on the development machine. How would I select a specific one?

Also, when enetering the first line of code you provided I get this error.

(SyntaxError) keyword argument must be followed by space after: python:
|
18 | {ok, PythonInstance1} = python:start()
| ^

Stacktrace:
│ (elixir 1.14.4) lib/kernel/parallel_compiler.ex:340: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7

kokolegorille

kokolegorille

No idea how is your setup…

But starting my release with Systemd, I can pass Python environment variables.

kokolegorille

kokolegorille

That is not Elixir code, but Erlang, it should be…

{:ok, pi1} = :python.start()

… in Elixir. And beware with the strings, they are not really the same between Elixir and Erlang

Tormenator1

Tormenator1 OP

I am using this exact line when i get the error above.

:python.start([{:python_path, to_charlist(path)}, {:python, 'python3'}])

Elixir thinks that this is a syntax error.

I get a similar error when I try this line from the language docs

{ok, P} = python:start()

(SyntaxError) keyword argument must be followed by space after: python:
|
18 | {ok, P} = python:start()
| ^

Stacktrace:
│ (elixir 1.14.4) lib/kernel/parallel_compiler.ex:340: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7

Why exactly would this be happening?

kokolegorille

kokolegorille

Erlport is an Erlang package, so the doc is written in Erlang…

I advise You to read this page, if You want to translate from Erlang to Elixir

kokolegorille

kokolegorille

No, I did not provide code written in Erlang :slight_smile:

Tormenator1

Tormenator1 OP

So the python file is called handler.py and the function I am calling is called hey. It accepts 1 string parameter.

How would I call that function in this code. I’m unclear about what is meant to be passed into the call function in terms of the module parameter?

{:ok, pi1} = :python.start()
:python.call(pi1,,hey,"hi") #left module blank,unsure what is passed there

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews