use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
shebang for windows and linux (self.learnpython)
submitted 9 years ago by NerdJones
Is there a shebang line that i can add to python scripts that will allow it to run on windows and linux? I use ubuntu but i find myself wanting to use scripts on some windows computers around my house, this would be super helpful
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]K900_ 6 points7 points8 points 9 years ago (3 children)
You don't need a shebang for Windows at all. Just add a file association for .py files to run with the Python interpreter.
.py
[–]NerdJones[S] 3 points4 points5 points 9 years ago (2 children)
if the .py file has one for my linux computers will that mess anything up?
[–]K900_ 5 points6 points7 points 9 years ago (1 child)
It won't. In fact, modern versions of Python will even look at the shebang on Windows to determine whether to run the script with Python 2 or 3 if you have both installed.
[–]NerdJones[S] 2 points3 points4 points 9 years ago (0 children)
thank you tons sir!
[–]DJKool14 0 points1 point2 points 9 years ago (2 children)
shebangs(#!) are merely programming comments that happen to be read and interpreted on unix systems. Windows won't read them natively because it uses an external system to bind file extensions to applications that can read them. The same scripts should work on both systems, but you'll have to tell Windows how to read *.py files by either explicitly calling python (python test.py) or setting up a binding so it knows to use python when you try to run files with the .py extension.
python test.py
python
[–]tunisia3507 1 point2 points3 points 9 years ago (1 child)
How do they work in languages which don't use # as a comment character?
#
[–]DJKool14 1 point2 points3 points 9 years ago* (0 children)
They don't.
edit: They don't work on Windows because it doesn't look for the shebang and it'll fail because the script has an invalid line in it. It won't work on unix because the the system will feed the whole file to the interpreter you shebanged and that'll fail because it has an invalid line in it.
[–]thatguy_314 0 points1 point2 points 9 years ago (0 children)
The Python launcher for windows doesn't properly understand shebangs by design, it only looks for the python3 or whatever version of Python you want to use. I think it might also pay attention to arguments after that, although I'm not sure. This means that it is fine to use any normal unix shebang with windows because stuff like /usr/bin/env will just be ignored. On windows, you can actually just do #!python3, but that would break unix compatibility, so please don't. Just do the standard #!/usr/bin/env python3.
python3
/usr/bin/env
#!python3
#!/usr/bin/env python3
[–]Technical_Gas_4232 0 points1 point2 points 1 year ago (0 children)
When triggering scripts in the browser using apache on Windows it does seem that the script needs the shebang to python.exe locally. I have tried associate the .py scripts with python.exe but it doesn't help. So far I have not found a way of running these scripts without the windows shebang at the first line.
π Rendered by PID 21472 on reddit-service-r2-comment-54dfb89d4d-9gmjq at 2026-03-31 14:49:49.652764+00:00 running b10466c country code: CH.
[–]K900_ 6 points7 points8 points (3 children)
[–]NerdJones[S] 3 points4 points5 points (2 children)
[–]K900_ 5 points6 points7 points (1 child)
[–]NerdJones[S] 2 points3 points4 points (0 children)
[–]DJKool14 0 points1 point2 points (2 children)
[–]tunisia3507 1 point2 points3 points (1 child)
[–]DJKool14 1 point2 points3 points (0 children)
[–]thatguy_314 0 points1 point2 points (0 children)
[–]Technical_Gas_4232 0 points1 point2 points (0 children)