I'm new to Python and programming in general. I'm trying to force my scripts to use Python3.4 as installed using the python installer from python.org.
My script has this.
#!/usr/local/bin/python3.4
import sys
print(sys.version)
print("Hello, World!")
Terminal returns this:
$ python pyscript.py
2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
Hello, World!
The shebang path is correct, according to "which python3.4"
By calling python on your script you are using the python in your path. As the comment suggests run the file directly after setting the execution bit.
Shebang is only used when you run your script directly using command like this
$ ./pyscript.py
When you python interpreter from command line, the shell doesn't consult shebang line. It simply runs the first python executable it finds on the command line.
To change the default python executable, adjust your path. Or better yet use python virtual environment. More information on virtual environment is here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With