简体   繁体   中英

Python Script Won't Run from Aws Ubuntu Terminal

I just set up my first aws server for a personal project I'm doing. I'm running ubuntu linux, and I have a python script that accesses an sqlite database file in order to send email. I have these same files on my own ubuntu machine and the script works fine. I'm having trouble, however, figuring out how to run my script from the terminal in my aws vm. Normally I use idle to run my python script on my linux machine, so I'm trying to figure out how to run it from the terminal and it's giving me some trouble.

I tried

python script.py

which did nothing, so I converted it to an executable, ran it, and got

./script.py: line 1: import: command not found
...and so on

I realized that I had to add

#!/usr/bin/env python3

to my script, so I did that, converted to executable again, and ran it by entering

./script.py

which also did nothing. If the program had run, it would have delivered an email to my inbox. Is there any way I can tell if it's actually trying to run my script? Or am I trying to run it incorrectly?

You can modify the script to add verbose that prints out to the console the status of the script, or if you just want to know whether your script is running in the background, you can check whether the process is active using ps (process name would be the name of the script) :

ps aux | grep "script.py"

Anyways the former is a better practice, since you can exactly know execution flow of your script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM