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
Mike Hansen
Python Web Development Techdegree Student 3,419 PointsHow 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
Mike Hansen
Python Web Development Techdegree Student 3,419 PointsJennifer Nordell that just gives me a permission denied
Mikes-MacBook-Pro:~ MikeHansen$ PycharmProjects/zestymemes/app.py -bash: PycharmProjects/zestymemes/app.py: Permission denied
Jennifer Nordell
Treehouse TeacherMike Hansen even using sudo?
Mike Hansen
Python Web Development Techdegree Student 3,419 PointsNo i'm only using the things he's using.
Mike Hansen
Python Web Development Techdegree Student 3,419 Pointsyou know i copied all his code and only downloaded all the pip things he told me to :)
Jennifer Nordell
Treehouse Teachersudo 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
Seth Kroger
56,416 PointsSince 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)
Mike Hansen
Python Web Development Techdegree Student 3,419 PointsSeth how do i use the chmod exactly?
Mike Hansen
Python Web Development Techdegree Student 3,419 PointsWell 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
Mike Hansen
Python Web Development Techdegree Student 3,419 PointsI found out how to do it now! :)
- Thanks for your help!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherSorry to check the obvious here, but have you navigated first to the directory containing the app.py file?