getting a bunch of errors with ./diary.py
my field seems to run fine when i type diary.py in my terminal. However, when i type chmod +x diary.py and then ./diary.py, I get the following errors:
./diary.py: line 1: import: command not found
./diary.py: line 3: from: command not found
./diary.py: line 5: syntax error near unexpected token `('
./diary.py: line 5: `db=SqliteDatabase('diary.db')'
can anyone explain why I am getting these errors?
SC3 Rocks30,961 Points
Kathryn Klarich Those don't look like errors generated by python to me. They look like errors generated by your shell, which is what runs "python" with arguments "diary.py" when you type in python diary.py.
How are you running your program? If you're doing
. diary.py or
. ./diary.py, note that
. is a command in most shells, which says "run this file in the current namespace" i.e. not what you want.
./diary.py still fails, double check that the first line is indeed
#!/usr/bin/env python3. If it is, and it's still not working, try running
/usr/bin/env python3 diary.py yourself and tell me how that goes.
Kenneth LoveTreehouse Guest Teacher
I'd have to see the code before I could answer definitively, but it sounds like it's maybe being run by the wrong version of Python? I'm really not sure how far back you'd have to go before
from X import Y wouldn't work, though.