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 Gettin' CRUD-y With It View and Search Entries

./diary.py - Nothing happens, in fact it says there is an error. Any help?

terminal question. I can't seem to follow along when it comes to enter inputs on the terminal window. What am I missing?

Steven Parker
Steven Parker
231,236 Points

You'll need to show your code so we can take a look. Use Markdown formatting when pasting in code, or share the entire workspace by making a snapshot and posting the link to it.

3 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

Not sure if this is your issue, but there is a bit of difference between Python 2.7.x and Python 3.x in terms of console input.

On Python 2.7.x:

name = raw_input("What is your name: ")

On Python 3.x

name = input("What is your name: ")

Hi Steven and Jeff, when i go to the console/workspace and type ./diary.py I get back /usr/bin/env: 'python3\r': No such file or directory

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

Treehouse workspaces are set up for Python3 by default now. You probably know some of this stuff below already, so if I am misinterpreting your question, I apologize in advance!

If you just want to run the code (and it is in your current directory), then type

$ python diary.py

Running as a script -- is OPTIONAL, but nice to know.

Linux and MacOSX terminal environments can vary quite a bit. On some Python 2.x is default, on others Python 3.x is default. So you will have to know a little about the local environment to get this working correctly.

This doesn't apply to Windows, as Python is not "native"... but easily installed at least.

If you want to run the file directly, you have to have a "shebang" and the absolute path to the python executable on the first line of the program. You also have to the execute flag set.

To find the python version and location:

treehouse:~/workspace$ python --version                                                   
Python 3.6.4                                                                              
treehouse:~/workspace$ which python                                                       
/usr/local/bin/python

The first line of your program MUST be this

#!/usr/local/bin/python

By default, a Python file created in a workspace is not set to be executable and then you have to change the execute flag on it:

note when I list the diary file, initially, its mask is set -rw-r--r--

I use the "chmod" program with +x argument

and the ready-to-run file mask is set -rwx-r-xr-x

treehouse:~/workspace$ ls -la diary.py                                                                 
-rw-r--r--. 1 treehouse users 47 May 20 17:10 diary.py                                                 
treehouse:~/workspace$ chmod +x diary.py                                                               
treehouse:~/workspace$ ls -la diary.py                                                                 
-rwxr-xr-x. 1 treehouse users 47 May 20 17:10 diary.py     

Now you should be able to run the program directly:

$ ./diary.py

I hope this helps!