Error on running python file on EC2 machine - python

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.

You have two different errors:
python oasis_live.py most likely is the python2.7 interpreter and the syntax is incompatible
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

You probably need to install the dependencies on the EC2 Instance too. Try to pip install all the dependencies that you need. Including discord (pip install discord)

Related

Can't import external packages with python

Title. It just doesn't recognize it. For example, I'm trying to make a discord bot with discord.py. I do the pip install thingy, and it just spits this out when I try to run my file:
Traceback (most recent call last):
File "C:\Users\Pixel\Desktop\Discord bot\bot.py". line 1, in <module>
import discord
ModuleNotFoundError: No module named 'discord'
It does exist, I checked: (C:\Python38\lib\site-packages\discord)
Am I doing something wrong here or am I just stupid? Thanks!
There are many possible reasons for this error. You might have multiple versions of Python running on your machine, so you could have installed the module in a version of Python that your code is not using.
Make sure you're using the write version of Python as your interpreter.
You could also try installing the module directly in whatever venv you're using by typing this command into the terminal in the same folder python3.9 -m pip install discord. Replace python3.9 with whatever version of Python you're using.

Not being able to run my python scripts that contain third-party modules using Win+R command

I am trying to run my code using Win+R.
I am able to run a python script without using third-party modules. But when I use some third-party module in my code it shows this error:
Traceback (most recent call last):
File "C:\Users\pkgar\Desktop\Newfolder\pw.py", line 6, in <module>
import sys,pyperclip
ModuleNotFoundError: No module named 'pyperclip'
Edit: I am able to run the code in VS code, but I am just curious how to run the code using Win+R command.It is running perfectly using Win+R command when I don't use pyperclip module at all.
you haven't installed pyperclip yet.
you can install it using pip install pyperclip on your cmd.
check this out
https://pypi.org/project/pyperclip/
and olso if pip itself hasn't installed yet use
https://pip.pypa.io/en/stable/installing/

No module called 'discord' found

I'm trying to make a discord bot. So I did 'pip install discord' and it installed successfully! I have added Python to PATH as well. now in the Python Shell, I typed, 'import discord'. Then I get this error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import discord
ModuleNotFoundError: No module named 'discord'
I have used 'pip install discord' again and again and it still doesn't work! My pip is also the latest version. I also uninstalled and installed python but still doesn't work! :(
Why does it not work? Please help me. Thanks!!
I think this is because it is
pip install discord.py and not
pip install discord.
If you are on Linux, try pip3 install discord.py (pip installs to python2 by default).
You can also see the official pypi project.
This should be a simple solution. A previous answer indicated to make sure that you use the correct, full module name when making the pip call to install the module, and this is imperative -- however, since you're still not seeing results there is clearly still an issue.
The first question is what is your python download? Did you install python through something like conda, or did you just install the language directly on your device without a facilitating package?
In the meantime (and especially if you don't know the answer to the above question), try this command in your terminal (not your python shell, just your command line):
pip freeze
This command is referenced from this link, in case you're curious, and should give you a list of all locally install non-default python packages. If you provide the result of this call, I am certain it will better facilitate the solving of this issue.
Me to, I got this error.
I solved it as follows:
import discord.abc
if you use linux and run the pip install command as non root but the start command as root you need to run the pip command also as root

Linux commands error as if they were python modules

I'm running arch and when I try to use aws in the terminal I get a python-like error:
Traceback (most recent call last):
File "/usr/bin/aws", line 19, in <module>
import awscli.clidriver
ModuleNotFoundError: No module named 'awscli'
This happened for pip as well which I resolved by python -m ensurepip but I don't know why it was like that in the first place. I even tried explicitly adding the path to aws to my PATH to no avail.
Well, pip and other applications are in fact python programs. Apparently you just lack the 'awscli' module. A first try would be just install this module.
Try this command
sudo pip install awscli --force-reinstall --upgrade

ModuleNotFoundError: No module named 'redis'

I tried to install redis-py lib via pip. It was installed successfully, but when I tried to import redis in python3 shell, I got the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'redis'
In python2 it gets imported with no errors.
I have tried all three pip, pip2, pip3 on my machine (ubuntu 17.10). Also I have python3.6 installed. I also tried easy_install
You are installing it in Python 2.7 (you have probably already know this). If python3.6 brings up the correct Python version on your system then this should work for you:
python3.6 -m pip install redis
If you are unsure what each pip version brings up you can use the which command to list the file path. This will give you a good indication as to where to look.
Also pip3.6 install redis might work but is not as secure as the above

Categories