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:

kokolegorille

kokolegorille

I updated the systemd script that start my application to include all path found with sys.path.

And now it works :slight_smile:

Thank You very much

kartheek

kartheek

You are welcome. Memories from the past - it was hell supporting python2 and python3 in production.

Just curious - you are using virtualenv in production ?

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement