[PYTHON] Shebang on Ubuntu 20.04

Python on Ubuntu 20.04

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.

Example of how to write shebang

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

Shebang on Ubuntu 20.04
Install TensorFlow on Ubuntu
Install PySide2 on Ubuntu
Install JModelica on Ubuntu
build Python on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Installing pyenv on ubuntu 16.04
Install Theano on Ubuntu 12.04
Install angr on Ubuntu 18.04
Install pip / pip3 on Ubuntu
Set up Python 3.4 on Ubuntu
I installed tensorRT on Ubuntu 18.04
Use matplotlib on Ubuntu 12 & Python
SoftwareRAID 0 on SereneLinux (Ubuntu 18.04 Desktop)
I installed ROS on Ubuntu 18.04
USB Wifi on Ubuntu 20.04LTS
Set matplotlib font on ubuntu
Put Python 3.x on Ubuntu
Rebuild kernel on Ubuntu 20.04 (on Azure)
Operate ubuntu on VScode (windows10)
Create command shortcuts on Ubuntu 16.04
Install GoLand IDE on Ubuntu
Display GUI messages on Ubuntu
Install OpenCV on Ubuntu + python
wsl Install PostgreSQL on Ubuntu 18.04
Introducing TensorFlow on Ubuntu + Python 2.7
[ROS] Install ROS (melodic) on Ubuntu (18.04)
Install Caffe on Ubuntu 14.04 (GPU)
Install Docker on WSL Ubuntu 18.04
Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Remove ubuntu installed on Windows 10 machine
Python 3.4 pyvenv fails on Ubuntu 14.04 LTS
Changed partition mount point on Ubuntu
Prepare Python development environment on Ubuntu
Install Mecab and mecab-python3 on Ubuntu 14.04
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Building a Python environment on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Introducing Python using pyenv on Ubuntu 20.04
Preparing python using vscode on ubuntu
Draw Japanese with matplotlib on Ubuntu
Mount S3 on Ubuntu with goofys
I tried Cython on Ubuntu on VirtualBox
Install fabric on Ubuntu and try
Using a serial console on Ubuntu 20.04
Run XGBoost on Bash on Ubuntu on Windows
I couldn't input Japanese on Ubuntu 20.04
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Notes on installing Ubuntu 18.04 on the XPS 15 7590
How to install Go on Ubuntu
Run Yocto on Ubuntu using QEMU.
Environment construction of "Tello_Video" on Ubuntu
ROS study # 1 Install ros-noetic on ubuntu 20.04
OpenCV3 & Python3 environment construction on Ubuntu
Build wxPython on Ubuntu 20.04 on raspberry pi 4