kokolegorille

kokolegorille

Python module not found with erlport in release mode

Hello everyone,

I do have a strange error happening when using erlport and python.

** (ErlangError) Erlang error: {:python, :"builtins.ModuleNotFoundError", 'No module named \'cv2\'', [' File "/export/koko/koko/_build/prod/rel/koko/lib/face_recon2-0.1.0/priv/python_scripts/face_recon2.py", line 1, in <module>\n import cv2\n', ' File "/export/koko/koko/_build/prod/rel/koko/lib/erlport-0.10.1/priv/python3/erlport/erlang.py", line 225, in _incoming_call\n f = __import__(mod, {}, {}, [objects[0]])\n', ' File "/export/koko/koko/_build/prod/rel/koko/lib/erlport-0.10.1/priv/python3/erlport/erlang.py", line 233, in _call_with_error_handler\n function(*args)\n']}
** (EXIT) an exception was raised:
** (stop) exited in: GenServer.call(#PID<0.2634.0>, {:recon_faces, "/export/koko/uploads/post_processing/MTY0NzczMjU3NzY1Nw/screenshots"}, :infinity)

I do have cv2 installed with opencv-python, opencv-contrib-python, but it looks like it does not find it.

What is strange is… it’s working in dev, it’s working with MIX_ENV=prod mix phx.server, but not when starting the release.

Did I forgot to set some python environment variables?

I start the erlport process with…

  @impl true
  def init(_) do
    path = Path.join([:code.priv_dir(:face_recon2), "python_scripts"])

    with {:ok, pid} <- :python.start([{:python_path, to_charlist(path)}, {:python, 'python3'}]) do
      Logger.info("[#{__MODULE__}] Started python worker #{inspect self()}")
      {:ok, pid}
    end
  end
...
  @impl true
  def handle_call({:recon_faces, path}, _from, pid) do
    result = case :python.call(pid, :face_recon2, :recon_faces, [path, training_set()]) do
      {'ok', map_message} -> {:ok, sanitize(map_message)}
      {'error', error} -> {:error, to_string(error)}
      any -> {:error, "Unknown error #{inspect any}"}
    end
    {:reply, result, pid}
  end

I know it’s very specific, but if someone can help me understand why the python3 cv2 library is not found, I’ll be very happy :slight_smile:

Thanks for taking time

Marked As Solved

kartheek

kartheek

Did you try setting PYTHONPATH env variable?

If it is working in one config and not working in other - you can check search path for modules:

import sys
sys.path

If you can diff sys.path in release and dev, may be you can find answer of what is missing?

Also Liked

kartheek

kartheek

Python searches for modules in following places:

  1. tries to find in current directory from where script is run or interpreter is run
  2. paths added using PYTHONPATH
  3. python runtime

When using virtual environments - source <venv>/bin/activate it adds <venv>/lib/python<version>/site-packages folder to the search path.

Additional paths can be added using PYTHONPATH. Erlport also injects PYTHONPATH if it is set.

I feel you will find answer in diff from sys.path in dev and release environments.

It is unable to resolve cv2 module - mostly it has something to do with module search path.

kokolegorille

kokolegorille

Thank You for your help, I will try and report.

Could You tell me more about this PYTHONPATH? For sure I did not use it :slight_smile:

kokolegorille

kokolegorille

Thank You,

I have found the path… unfortunately, I cannot test it yet, because someone is working on the site.

But it looks this should solve the problem :slight_smile:

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement