Friday, February 4, 2022

[SOLVED] Error on running python file on EC2 machine

Issue

I am trying to run a python file on an EC2 machine with Amazon Linux installed. I used putty to connect and when I try to run the file I get this output.

[ec2-user@myIP ~]$ python oasis_live.py
  File "oasis_live.py", line 36
    async def on_ready(self):
            ^
SyntaxError: invalid syntax
[ec2-user@myIP ~]$ python3 oasis_live.py
Traceback (most recent call last):
  File "oasis_live.py", line 3, in <module>
    import discord
ModuleNotFoundError: No module named 'discord'
[ec2-user@myIP ~]$

This is very confusing to me since the code works perfectly fine on my PC.


Solution

You have two different errors:

  1. python oasis_live.py most likely is the python2.7 interpreter and the syntax is incompatible
  2. python3 oasis_live.py is the python3.x interpreter, which probably is the one you want to use since you use async functions. Your code seems to rely on a 3rd party dependency called discord. To use that, you need to install it first, e.g. with pip3 install discord


Answered By - Maurice
Answer Checked By - Willingham (WPSolving Volunteer)