Ubuntu 20.04 is out. Immediately ~~ Playing ~~ After investigating, it seems that Python3.8 is included in the standard installation. However, it does not start with python, it starts with python3. [^ 1] Normally, it's not a problem, but when you want to start it as an executable file using the shebang [^ 2] function, it's a little troublesome. What should I do? I did some research by saying that.
After a lot of searching, I found How to write the correct shebang in Perl, Python and Ruby scripts. It looks like how to start / bin / sh and start python with exec [^ 3]. [^ 4] I played with this a little.
\#!/bin/sh
""":" .
if [ -x python ] ; then
exec python "$0" ${1+"$@"}
else
exec python3 "$0" ${1+"$@"}
fi
"""
import sys
__doc__ = """
The above defines the script's __doc__ string. You can fix it by like this."""
def main():
print('exec ok')
for v in sys.argv:
print(v)
if __name__ == '__main__':
main()
For the time being, this is the way to start with either python or python3. …… But I'm not sure if I need to do this (^^ ゞ CentOS8 With CentOS8, python / python3 is not included by default, so it will not start. Yum / dnf seems to be running platform-python, but if that's the case, I should have made it work in a virtual environment around venv, but it's not surprising.
[^ 1]: Insert the python-is-python3 package and it will start.
[^ 2]: For example, #! / Usr / bin / env python
on the first line.
[^ 3]: Originally it seems to be the method when / usr / bin / env does not exist
[^ 4]: What does the first part " "": ".
mean?
Recommended Posts