Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a python script with pm2 error

First of all, sorry if this is a duplicate, i've searched, found some fixes but i'm dumb and could not apply. I'm not a developer, programmer, just trying to run a python script that does some things .I've got basic understanding of python so speak to me like i'm dumb.

These are the dependencies that makes the bot run . Running python3 bot.py runs ok, but i need some thingy that restarts the program when it dies, and pm2 seems easy for a moron like me.

import discord
import asyncio
import datetime
import os
import json
import requests
from coinmarketcap import Market
from steem import Steem
from steem.post import Post
from steem.blog import Blog
from steem.instance import set_shared_steemd_instance
from steem.account import Account
from steem.steemd import Steemd
from discord.ext.commands import Bot
from discord.ext import commands

When i run pm2 start bot.py This is what i get pm2 ls ┌──────┬──────┬─────────┬────┬─────┬────────┐ │ Name │ mode │ status │ ↺ │ cpu │ memory │ ├──────┼──────┼─────────┼────┼─────┼────────┤ │ bot │ fork │ errored │ 15 │ 0% │ 0 B

I've read that pm2 should identify the .py and run the script, so why isn't it working like it's supposed to?

pm2 -v 2.10.1 Running ubuntu 16.04 LTS

like image 887
Serbanescu Claudiu Avatar asked Jan 03 '23 17:01

Serbanescu Claudiu


1 Answers

Since I haven't really seen my solution for this problem, and there was no solution verified, I'll give mine. Hope it helps!

While it is true pm2 is made for Node.js, it is possible to run Python scripts. I've been doing it for a while, and it's quite alright!

I also read pm2 should be auto-detecting the .py in your file, but to my experience it doesn't do a good job at detecting python3. Specifying which interpreter to use helps in my case.

You do this by adding following parameter: --interpreter python3. So in your case the full command would be pm2 start bot.py --interpreter python3.

like image 146
Adriaan Vermeire Avatar answered Jan 05 '23 05:01

Adriaan Vermeire