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
john larson
16,594 Pointstrying to get access to python scripts on windows from the bash shell
- C:\Users\smolderingflax\AppData\Local\Programs\Python\Python35-32\Scripts\
- I've made it to this place: Edit environment variable
- Is this where I would add bash to the path?
- if so would it just look like \bash added to the end?
- and would that make it so I could run scripts on windows from bash
- If my questions are nonsensicle it's because I'm entirely in the dark
- Thank you
1 Answer
Steven Parker
243,253 Points
You can run Python scripts directly from bash.
- if you're using bash, the slashes should go the other way ("
/" instead of "\") - you would add the directory containing the scripts to the path
- you would not add "/bash" to the path or a directory name in the path
- to run python scripts from bash, you need to add an explicit interpreter directive to each python file
If the program is a file beginning with "#!", the remainder of the first
line specifies an interpreter for the program. The bash shell executes the
specified interpreter on operating systems that do not handle this
executable format themselves.
So if your Python program was located at C:\Python\Python.exe, you might place this line at the beginning of your python script file:
#! C:/Python/Python.exe
Then, you could just type the name of the python script into bash and it would start running.
john larson
16,594 Pointsjohn larson
16,594 PointsHi Steve, so this line:
#! C:/Python/Python.exeis at the top of my script, I tried two ways:
I'm clearly missing some key points here. I did the whole python course on the windows cmd. Then I heard that I really need to learn to use bash. So that's what I'm trying to do now. I went through the console foundations course. But I still can't seem to get this. So... I appreciate your help.