Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
16,178 Points

Can you post a snapshot of your workspace?

Kenneth Love please tell this question

2 Answers

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.