Linked Questions
86 questions linked to/from Should I put #! (shebang) in Python scripts, and what form should it take?
0
votes
1
answer
2k
views
How to get a python script to run as an executable? [duplicate]
I would like to run my python script as an executable from the command line, usually when I do a bash script I added this to the top of the file:
#!/bin/bash
Then I made the script executable with:
...
0
votes
0
answers
2k
views
Difference between "main.py" and "python main.py" in command prompt [duplicate]
I would like to understand what is the difference between the two commands
python main.py and main.py to run the main.py file in the command prompt; and which to use in what circumstance.
1
vote
0
answers
575
views
Attempting to make python file executable on mac. Bad interpreter, permission denied [duplicate]
I'm learning python and I'm attempting to make a python file executable. This is the code
#! /Users/<me>/PycharmProjects/untitled3
print ("Hello World")
in the terminal I typed.
$ chmod +x ...
1
vote
0
answers
161
views
What does the first line ("#!..") in a CGI script do? [duplicate]
I am using Python in Apache on a Raspberry Pi. The first line of the Python files has the following line:
#!/usr/bin/env python
What does it mean? The /usr/bin/env folder contains no files. My ...
1
vote
0
answers
151
views
How can I execute python file? [duplicate]
I made test.py and ran chmod u+x test.py. It works if I run python test.py but not ./test.py. What am I doing wrong?
./test.py: line 1: syntax error near unexpected token `"HelloWorld"'
./test.py: ...
0
votes
0
answers
73
views
Is this headline '#!/usr/bin/env python3' still needed from python 3.6 and onwards? [duplicate]
Since python 3 is using utf-8 encoding by default, the headline # -*- coding: utf-8 -*- is not needed anymore. However, what about the line #!/usr/bin/env python3 on Unix system?
To my knowledge, this ...
0
votes
0
answers
67
views
Monterey. zsh: ./flashimage.py: bad interpreter: /usr/bin/python: no such file or directory [duplicate]
I'm having issues running a .py script.
The full error I get is zsh: ./flashimage.py: bad interpreter: /usr/bin/python: no such file or directory
Below are details of my system and files.
I see I have ...
1391
votes
22
answers
1.1m
views
Why do people write "#!/usr/bin/env python" on the first line of a Python script?
I see these at the top of Python files:
#!/usr/bin/env python
#!/usr/bin/env python3
It seems to me that the files run the same without that line.
326
votes
7
answers
469k
views
"SyntaxError: Non-ASCII character ..." or "SyntaxError: Non-UTF-8 code starting with ..." trying to use non-ASCII text in a Python script
I tried this code in Python 2:
def NewFunction():
return '£'
But I get an error message that says:
SyntaxError: Non-ASCII character '\xa3' in file '...' but no encoding declared;
see http://www....
200
votes
15
answers
548k
views
Python can't find module in the same folder
My python somehow can't find any modules in the same directory.
What am I doing wrong? (python2.7)
So I have one directory '2014_07_13_test', with two files in it:
test.py
hello.py
where hello.py:
#...
71
votes
8
answers
110k
views
env: python\r: No such file or directory
My Python script beak contains the following shebang:
#!/usr/bin/env python
When I run the script $ ./beak, I get
env: python\r: No such file or directory
I previously pulled this script from a ...
33
votes
8
answers
19k
views
Git 2.5.1's bash console doesn't open python interpreter
If I do it in CMD, it works without issues, but if I try it in Git Bash it doesn't work. I like to use Git Bash as my only console, but I can't do that if it doesn't work with Python 3.4.
Example is ...
78
votes
1
answer
27k
views
What's the difference between python shebangs with /usr/bin/env rather than hard-path?
I used to use the shebang
#!/usr/bin/env python
When is it better to use
#!/usr/bin/python
What is the exact difference between them?
69
votes
1
answer
54k
views
Proper shebang for Python script
I'm usually using the following shebang declaration in my Python scripts:
#!/usr/bin/python
Recently, I've came across this shebang declaration:
#!/usr/bin/env python
In the script documentation, it ...
57
votes
3
answers
36k
views
How do you organise a python project that contains multiple packages so that each file in a package can still be run individually?
TL;DR
Here's an example repository that is set up as described in the first diagram (below): https://github.com/Poddster/package_problems
If you could please make it look like the second diagram in ...