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

How to open .py on local machine?

Hi, i'm on my mac and downloaded python on my local machine then downloaded PyCharm and began to follow. Now one question i have is, how do i open app.py via my terminal? I of course tried python app.py in the terminal but that just gave me: python: can't open file 'app.py': [Errno 2] No such file or directory

Hope you can help me out

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Sorry to check the obvious here, but have you navigated first to the directory containing the app.py file?

Jennifer Nordell that just gives me a permission denied

Mikes-MacBook-Pro:~ MikeHansen$ PycharmProjects/zestymemes/app.py -bash: PycharmProjects/zestymemes/app.py: Permission denied

No i'm only using the things he's using.

you know i copied all his code and only downloaded all the pip things he told me to :)

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

sudo is a command (Should be included on your Mac) that means super user do. This allows you to run the app with super user privileges. I highly recommend you take a small detour from python (you don't have to switch tracks) and go through this course here at Treehouse. They'll have you using that command line like a pro in about 225 minutes :smile:

https://teamtreehouse.com/library/console-foundations

Since you are trying to run the script directly, have you tried python app.py or python3 app.py (python3 might be installed along with python 2)

To start it directly script needs 1) the line #!/usr/bin/env python at the very first line, and 2) needs to be chmod'ed to be executable. (chmod +x app.py)

Seth how do i use the chmod exactly?

Well Seth i wrote this in the terminal:

os.chmod(#!/usr/vin/env python3, stat.S_IEXEC)

and when i do that it just says:

and when i try to say app.py or python3 app.py etc. it just gives me an error like this: File "<stdin>", line 4 python3 app.py ^

or

python app.py File "<stdin>", line 1 python app.py

1 Answer

I found out how to do it now! :)

  • Thanks for your help!