Python Using Databases in Python Our Diary App Doing Data Entry

Why did I get No such file or directory when trying to run ./diary.py?

I am working in the site Workspaces. I see that my question includes the place in which I am working and where I was last trying to do something. So, I added the !# at the top of diary.py, I added +x permission. Then I tried to run ./diary.py and got an error saying that No such File or directory. Bruce

5 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 56,801 Points

Hi Bruce, You've added a "bang-she" (!#), instead of a shebang (#!). How I remember is an exclamation point is sometimes called a "bang" so a shebang should end in a bang!. also add the full shebang #!/usr/bin/env python3

I type it exactly, but I'm having the same problem. Below is my diary.py

#!/usr/bin/env python3

import datetime

from peewee import *

db = SqliteDatabase('diary.db')

class Entry(Model):
    content = TextField()
    timestamp = DateTimeField(default=datetime.datetime.now)

    class Meta:
        database = db

def initialize():
  """Create the database and table if they don't exist"""
  db.connect()
  db.create_tables([Entry], safe=True)

def menu_loop():
    """Show the menu"""

def add_entry():
    """Add an entry"""

def view_entries():
    """View an entry"""

def delte_entry(entry):
    """Delete an entry"""

if __name__ == '__main__':
    initialize()
    menu_loop()
Chris Freeman
Chris Freeman
Treehouse Moderator 56,801 Points

Jason, are running this in Win, in Mac, in Linux, or In Workspaces?

Gabbie Metheny
Gabbie Metheny
33,669 Points

It looks like this was resolved in this question by Iain Simmons . Kenneth Love , is it possible to add this to the teacher's notes for the video? It looks like it's a pretty common issue.

If you run the code in the video and get "No such file or directory":

treehouse:~/workspace$ chmod +x diary.py                                                            
treehouse:~/workspace$ ./diary.py                                                                   
: No such file or directory 

Try running the following line, then the two lines from above again:

sed -i 's/\r//g' diary.py
Chris Freeman
Chris Freeman
Treehouse Moderator 56,801 Points

Tagging Craig Dennis who is pickup Python coverage since Kenneth left Treehouse

I have this same problem in Workspaces. Not the bang she, but the : No such file or directory. Any suggestions? Chris Freeman Kenneth Love

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

It can't find the database file? Can you copy and paste the entire error message?

stephenmelendy
stephenmelendy
3,578 Points

I am having the same error.

Here is my console:

treehouse:~/workspace$ chmod +x diary.py                                                            
treehouse:~/workspace$ ./diary.py                                                                   
: No such file or directory                                                                         
treehouse:~/workspace$ ls                                                                           
diary.db  diary.py  students.db  students.py                                                        
treehouse:~/workspace$   

Here is a copy of my code at top:

#!/usr/bin/env python3

from peewee import *

import datetime

db = SqliteDatabase('diary.db')
Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Hmm, I wonder if something has changed in how Peewee or sqlite3 finds the database file?

Try giving an explicit path: db = SqliteDatabase('./diary.db')

If that doesn't work, we can find the path with os.path but let's leave that for later.

stephenmelendy
stephenmelendy
3,578 Points

Hi Kenneth, thank you for the reply. The explicit path didn't work, but if this is only the difference between typing "python diary.py" vs "./diary.py", I am perfectly fine leaving it as a peculiarity.

Gabbie Metheny
Gabbie Metheny
33,669 Points

Kenneth, I am receiving the exact same error message as the others here, and the explicit path did not work. Have you had any insight into this problem since February? Thank you!