0

My server system is Debian. I use pm2 to manage the process.
One of the processes is a python backend.
I have created a venv environment for it and activated it. I use this command to change ownership of the directory.

sudo chown myuser /var/www/mybackendcode.


This is my command to start my pm2 process

pm2 start /var/www/mybackendcode/serve.py --interpreter "/var/www/mybackendcode/venv/bin/python3.8" --name HD-backend

It seems that the pm2 process can start successfully, but when I check the status again. The process showed errored.

I check the pm2 log of this process.

Traceback (most recent call last):
26|HD-back |   File "/var/www/home_delicious/home_delicious_backend/serve.py", line 1, in <module>
26|HD-back |     import bjoern
26|HD-back | ModuleNotFoundError: No module named 'bjoern'

This error message also appears when I run “python3.8 serve.py” to start the server directly.
But when I use "sudo python3.8 serve.py”. the server can be started successfully.

What is the problem? and How can I fix it? Thanks very much!

  • 1
    Do you installed pip already?, with that you can install any dependency like bjoern with "pip/pip3 install bjoern" and that's it https://pypi.org/project/bjoern/ – Omar Alvarado Sep 23 '22 at 22:43
  • Yes, I have installed and I install bjoern and other libs using pip. And I can use "sudo python3.8 serve.py" to start the server. So the guess if this is the problem of permission to access python module? – Liang Tang Sep 24 '22 at 00:07
  • if you use `sudo python3.8` to run it then use it also to install modules `sudo python3.8 -m pip install ...` because you may have many Pythons installed and `sudo python3.8` may run different Python than `pip/pip3` - but different Pythons don't share modules. – furas Sep 24 '22 at 16:04
  • Thanks, I fixed it. So when I install the lib use `sudo` or nor is install different and they are not shared! – Liang Tang Sep 25 '22 at 16:03

0 Answers0