I am running Prefect docker agent in supervisor. B...
# prefect-community
n
I am running Prefect docker agent in supervisor. But I am getting following error: ModuleNotFoundError: No Module named prefect at line "from prefect.cli import cli". Anyone faced similar issue?
a
What base image do you use? Is it an official Prefect base image? https://hub.docker.com/r/prefecthq/prefect Also, you would need to give more info: 1. how you installed prefect on the instance, 2. are you running this on your laptop? 3. on which system (unix, windows)? 4. are you on Prefect Cloud or Server? 5. do you get this error when starting the agent or when running/registering a flow? Also, check out our install and Docker agent docs for more info
n
Thanks for replying. Here are the answers for your question : 1. how you installed prefect on the instance? Using Pip install prefect 2. are you running this on your laptop? Its on a VM running on my laptop 3. on which system (unix, windows)? unix 4. are you on Prefect Cloud or Server? Prefect Cloud 5. do you get this error when starting the agent or when running/registering a flow?' It is coming while starting the agent using supervisor. When I run the command "prefect agent docker start" in my terminal it starts sucessfully. Here is the supervisor config file [unix_http_server] file=/var/run/supervisor.sock ; the path to the socket file [supervisord] loglevel=debug ; log level; default info; others: debug,warn,trace [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///var/run.supervisor.sock ; use a unix:// URL for a unix socket [program:prefect-agent] command=/home/nitin/.local/bin/prefect agent docker start --key mykey -f --agent-address http://localhost:8081
Here is the snapshot of the error
May be this error is coming because I am starting supervisor in sudo mode like below
But when I start it without SUDO I am getting the following error
a
Thank you for the excellent problem description. You're right that running this process with
sudo
is the culprit. I learned just yesterday that if you're running this with sudo, you’re accessing a different Prefect home directory with different settings. I think what may help here is when you create a virtual environment (e.g. with Conda) and when you don't run the supervisord in
/etc
but rather in some normal home directory. E.g. I have a project in
~/repos/myproject
and within this directory I created a file called
supervisord.conf
that looks as follows:
Copy code
[unix_http_server]
file=/tmp/supervisor.sock   ; the path to the socket file

[supervisord]
loglevel=debug               ; log level; default info; others: debug,warn,trace

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:prefect-agent]
command=/Users/anna/opt/anaconda3/envs/myCondaVenv/bin/prefect agent docker start --key KEY -l docker
Beforehand, I created a conda env
myCondaVenv
as referenced above. Then, since this is all in my project dir (rather than /etc) I can execute the supervisor process without sudo:
Copy code
supervisord -c ./supervisord.conf
Let me know if you can replicate this setup.