Python Using Databases in Python Our Diary App Doing Data Entry

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?

Thanks!

Kathryn

Benjamin Lange
Benjamin Lange
Pro Student 16,019 Points

Can you post a snapshot of your workspace?

vikas pal
vikas pal
8,545 Points

Kenneth Love please tell this question

2 Answers

SC3 Rocks
SC3 Rocks
30,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.

If ./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.

Thanks! the second method worked for me.

Kenneth Love
STAFF
Kenneth Love
Treehouse 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.