Ubuntu Desktop 日本語 Remixを「最小インストール」でインストールしましたがpython3がすでにインストールされていました。
How To Install Python 3 and Set Up a Programming Environment on an Ubuntu 20.04 Server
https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-programming-environment-on-an-ubuntu-20-04-server
Ubuntu 20.04 and other versions of Debian Linux ship with Python 3 pre-installed. To make sure that our versions are up-to-date, update your local package index
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
rootlinks@Ubuntu20:~$ python3 --version Python 3.8.10 rootlinks@Ubuntu20:~$ sudo apt list --installed | grep python WARNING: apt does not have a stable CLI interface. Use with caution in scripts. libpython3-stdlib/focal,now 3.8.2-0ubuntu2 amd64 [installed,automatic] libpython3.8-minimal/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.2 amd64 [installed,automatic] libpython3.8-stdlib/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.2 amd64 [installed,automatic] libpython3.8/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.2 amd64 [installed,automatic] python-apt-common/focal-updates,focal-updates,now 2.0.0ubuntu0.20.04.6 all [installed,automatic] python3-apport/focal-updates,focal-updates,focal-security,focal-security,now 2.20.11-0ubuntu27.21 all [installed,automatic] python3-apt/focal-updates,now 2.0.0ubuntu0.20.04.6 amd64 [installed,automatic] python3-aptdaemon.gtk3widgets/focal-updates,focal-updates,focal-security,focal-security,now 1.1.1+bzr982-0ubuntu32.3 all [installed,automatic] python3-aptdaemon/focal-updates,focal-updates,focal-security,focal-security,now 1.1.1+bzr982-0ubuntu32.3 all [installed,automatic] python3-argcomplete/focal,focal,now 1.8.1-1.3ubuntu1 all [installed,automatic] python3-blinker/focal,focal,now 1.4+dfsg1-0.3ubuntu1 all [installed,automatic] python3-breezy/focal,now 3.0.2-4ubuntu2 amd64 [installed,automatic] python3-brlapi/focal,now 6.0+dfsg-4ubuntu6 amd64 [installed,automatic] python3-cairo/focal,now 1.16.2-2ubuntu2 amd64 [installed,automatic] python3-certifi/focal,focal,now 2019.11.28-1 all [installed,automatic] python3-cffi-backend/focal,now 1.14.0-1build1 amd64 [installed,automatic] python3-chardet/focal,focal,now 3.0.4-4build1 all [installed,automatic] python3-click/focal,focal,now 7.0-3 all [installed,automatic] python3-colorama/focal,focal,now 0.4.3-1build1 all [installed,automatic] python3-commandnotfound/focal-updates,focal-updates,now 20.04.4 all [installed,automatic] python3-configobj/focal,focal,now 5.0.6-4 all [installed,automatic] python3-cryptography/focal-updates,focal-security,now 2.8-3ubuntu0.1 amd64 [installed,automatic] python3-cups/focal,now 1.9.73-3build1 amd64 [installed,automatic] python3-cupshelpers/focal-updates,focal-updates,now 1.5.12-0ubuntu1.1 all [installed,automatic] python3-dateutil/focal,focal,now 2.7.3-3ubuntu1 all [installed,automatic] python3-dbus/focal,now 1.2.16-1build1 amd64 [installed,automatic] python3-debconf/focal,focal,now 1.5.73 all [installed,automatic] python3-debian/focal,focal,now 0.1.36ubuntu1 all [installed,automatic] python3-debianbts/focal,focal,now 3.0.2 all [installed,automatic] python3-defer/focal,focal,now 1.0.6-2.1 all [installed,automatic] python3-deprecated/focal,focal,now 1.2.7-1 all [installed,automatic] python3-distro-info/focal,focal,now 0.23ubuntu1 all [installed,automatic] python3-distro/focal,focal,now 1.4.0-1 all [installed,automatic] python3-distupgrade/focal-updates,focal-updates,now 1:20.04.36 all [installed,automatic] python3-dns/focal,focal,now 3.2.1-1 all [installed,automatic] python3-dulwich/focal,now 0.19.15-1build1 amd64 [installed,automatic] python3-entrypoints/focal,focal,now 0.3-2ubuntu1 all [installed,automatic] python3-fastimport/focal,focal,now 0.9.8-5build1 all [installed,automatic] python3-gdbm/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04 amd64 [installed,automatic] python3-gi-cairo/focal,now 3.36.0-1 amd64 [installed,automatic] python3-gi/focal,now 3.36.0-1 amd64 [installed,automatic] python3-github/focal,focal,now 1.43.7-1 all [installed,automatic] python3-gitlab/focal,focal,now 1:2.0.1-1 all [installed,automatic] python3-gnupg/focal,focal,now 0.4.5-2 all [installed,automatic] python3-gpg/focal,now 1.13.1-7ubuntu2 amd64 [installed,automatic] python3-httplib2/focal,focal,now 0.14.0-1ubuntu1 all [installed,automatic] python3-ibus-1.0/focal-updates,focal-updates,now 1.5.22-2ubuntu2.1 all [installed,automatic] python3-idna/focal,focal,now 2.8-1 all [installed,automatic] python3-jwt/focal,focal,now 1.7.1-2ubuntu2 all [installed,automatic] python3-keyring/focal,focal,now 18.0.1-2ubuntu1 all [installed,automatic] python3-launchpadlib/focal,focal,now 1.10.13-1 all [installed,automatic] python3-lazr.restfulclient/focal,focal,now 0.14.2-2build1 all [installed,automatic] python3-lazr.uri/focal,focal,now 1.0.3-4build1 all [installed,automatic] python3-ldb/focal-updates,focal-security,now 2:2.2.3-0ubuntu0.20.04.2 amd64 [installed,automatic] python3-louis/focal,focal,now 3.12.0-3 all [installed,automatic] python3-macaroonbakery/focal,focal,now 1.3.1-1 all [installed,automatic] python3-magic/focal,focal,now 2:0.4.15-3 all [installed,automatic] python3-minimal/focal,now 3.8.2-0ubuntu2 amd64 [installed,automatic] python3-nacl/focal,now 1.3.0-5 amd64 [installed,automatic] python3-netifaces/focal,now 0.10.4-1ubuntu4 amd64 [installed,automatic] python3-oauthlib/focal,focal,now 3.1.0-1ubuntu2 all [installed,automatic] python3-olefile/focal,focal,now 0.46-2 all [installed,automatic] python3-pexpect/focal,focal,now 4.6.0-1build1 all [installed,automatic] python3-pil/focal-updates,focal-security,now 7.0.0-4ubuntu0.4 amd64 [installed,automatic] python3-pkg-resources/focal,focal,now 45.2.0-1 all [installed,automatic] python3-problem-report/focal-updates,focal-updates,focal-security,focal-security,now 2.20.11-0ubuntu27.21 all [installed,automatic] python3-progressbar/focal,focal,now 2.5-2 all [installed,automatic] python3-protobuf/focal,now 3.6.1.3-2ubuntu5 amd64 [installed,automatic] python3-ptyprocess/focal,focal,now 0.6.0-1ubuntu1 all [installed,automatic] python3-pyatspi/focal,focal,now 2.36.0-1 all [installed,automatic] python3-pycurl/focal,now 7.43.0.2-1ubuntu5 amd64 [installed,automatic] python3-pymacaroons/focal,focal,now 0.13.0-3 all [installed,automatic] python3-pysimplesoap/focal,focal,now 1.16.2-2 all [installed,automatic] python3-renderpm/focal,now 3.5.34-1ubuntu1 amd64 [installed,automatic] python3-reportbug/focal,focal,now 7.6.0ubuntu1 all [installed,automatic] python3-reportlab-accel/focal,now 3.5.34-1ubuntu1 amd64 [installed,automatic] python3-reportlab/focal,focal,now 3.5.34-1ubuntu1 all [installed,automatic] python3-requests-unixsocket/focal,focal,now 0.2.0-2 all [installed,automatic] python3-requests/focal,focal,now 2.22.0-2ubuntu1 all [installed,automatic] python3-rfc3339/focal,focal,now 1.1-2 all [installed,automatic] python3-secretstorage/focal,focal,now 2.3.1-2ubuntu1 all [installed,automatic] python3-simplejson/focal,now 3.16.0-2ubuntu2 amd64 [installed,automatic] python3-six/focal,focal,now 1.14.0-2 all [installed,automatic] python3-software-properties/focal-updates,focal-updates,now 0.99.9.8 all [installed,automatic] python3-speechd/focal,focal,now 0.9.1-4 all [installed,automatic] python3-systemd/focal,now 234-3build2 amd64 [installed,automatic] python3-talloc/focal-updates,focal-security,now 2.3.1-0ubuntu0.20.04.1 amd64 [installed,automatic] python3-tz/focal,focal,now 2019.3-1 all [installed,automatic] python3-ubuntutools/focal-updates,focal-updates,now 0.176ubuntu20.04.1 all [installed,automatic] python3-unidiff/focal,focal,now 0.5.5-2 all [installed,automatic] python3-update-manager/focal-updates,focal-updates,now 1:20.04.10.9 all [installed,automatic] python3-urllib3/focal-updates,focal-updates,focal-security,focal-security,now 1.25.8-2ubuntu0.1 all [installed,automatic] python3-wadllib/focal,focal,now 1.3.3-3build1 all [installed,automatic] python3-wrapt/focal,now 1.11.2-2build1 amd64 [installed,automatic] python3-xdg/focal,focal,now 0.26-1ubuntu1 all [installed,automatic] python3-xkit/focal,focal,now 0.5.0ubuntu4 all [installed,automatic] python3-yaml/focal-updates,focal-security,now 5.3.1-1ubuntu0.1 amd64 [installed,automatic] python3.8-minimal/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.2 amd64 [installed,automatic] python3.8/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.2 amd64 [installed,automatic] python3/focal,now 3.8.2-0ubuntu2 amd64 [installed,automatic] |
1 2 3 4 |
rootlinks@Ubuntu20:~$ python --version -bash: /usr/bin/python: No such file or directory rootlinks@Ubuntu20:~$ ls -l /usr/bin/python ls: cannot access '/usr/bin/python': No such file or directory |
pythonでエラーになったのでpython-is-python3をインストールしてリンクを張ります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
rootlinks@Ubuntu20:~$ sudo apt install python-is-python3 Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: python-is-python3 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 2364 B of archives. After this operation, 10.2 kB of additional disk space will be used. Get:1 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 python-is-python3 all 3.8.2-4 [2364 B] Fetched 2364 B in 0s (19.1 kB/s) Selecting previously unselected package python-is-python3. (Reading database ... 181032 files and directories currently installed.) Preparing to unpack .../python-is-python3_3.8.2-4_all.deb ... Unpacking python-is-python3 (3.8.2-4) ... Setting up python-is-python3 (3.8.2-4) ... |
1 2 3 4 |
rootlinks@Ubuntu20:~$ python --version Python 3.8.10 rootlinks@Ubuntu20:~$ ls -l /usr/bin/python lrwxrwxrwx 1 root root 7 Apr 15 2020 /usr/bin/python -> python3 |
プログラミングパッケージ管理のpipをインストール
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
rootlinks@Ubuntu20:~$ pip Command 'pip' not found, but can be installed with: sudo apt install python3-pip rootlinks@Ubuntu20:~$ sudo apt install python3-pip Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libexpat1-dev libpython3-dev libpython3.8-dev python-pip-whl python3-dev python3-distutils python3-lib2to3 python3-setuptools python3-wheel python3.8-dev zlib1g-dev Suggested packages: python-setuptools-doc The following NEW packages will be installed: libexpat1-dev libpython3-dev libpython3.8-dev python-pip-whl python3-dev python3-distutils python3-lib2to3 python3-pip python3-setuptools python3-wheel python3.8-dev zlib1g-dev 0 upgraded, 12 newly installed, 0 to remove and 0 not upgraded. Need to get 7347 kB of archives. After this operation, 29.1 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libexpat1-dev amd64 2.2.9-1build1 [116 kB] (snip) Setting up python3-wheel (0.34.2-1) ... Setting up libexpat1-dev:amd64 (2.2.9-1build1) ... Setting up libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.2) ... Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.2) ... Setting up python-pip-whl (20.0.2-5ubuntu1.6) ... Setting up python3-lib2to3 (3.8.10-0ubuntu1~20.04) ... Setting up python3-distutils (3.8.10-0ubuntu1~20.04) ... Setting up libpython3-dev:amd64 (3.8.2-0ubuntu2) ... Setting up python3-setuptools (45.2.0-1) ... Setting up python3-pip (20.0.2-5ubuntu1.6) ... Setting up python3.8-dev (3.8.10-0ubuntu1~20.04.2) ... Setting up python3-dev (3.8.2-0ubuntu2) ... Processing triggers for man-db (2.9.1-1) ... |
1 2 3 4 |
rootlinks@Ubuntu20:~$ pip --version pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8) rootlinks@Ubuntu20:~$ pip3 --version pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8) |
プログラミング環境をさらに充実させるために追加インストール
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
rootlinks@Ubuntu20:~$ sudo apt install -y build-essential libssl-dev libffi-dev python3-dev Reading package lists... Done Building dependency tree Reading state information... Done python3-dev is already the newest version (3.8.2-0ubuntu2). python3-dev set to manually installed. build-essential is already the newest version (12.8ubuntu1.1). Suggested packages: libssl-doc The following NEW packages will be installed: libffi-dev libssl-dev 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 1641 kB of archives. After this operation, 8321 kB of additional disk space will be used. Get:1 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 libssl-dev amd64 1.1.1f-1ubuntu2.10 [1584 kB] Get:2 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libffi-dev amd64 3.3-4 [57.0 kB] Fetched 1641 kB in 1s (2232 kB/s) Selecting previously unselected package libssl-dev:amd64. (Reading database ... 181900 files and directories currently installed.) Preparing to unpack .../libssl-dev_1.1.1f-1ubuntu2.10_amd64.deb ... Unpacking libssl-dev:amd64 (1.1.1f-1ubuntu2.10) ... Selecting previously unselected package libffi-dev:amd64. Preparing to unpack .../libffi-dev_3.3-4_amd64.deb ... Unpacking libffi-dev:amd64 (3.3-4) ... Setting up libffi-dev:amd64 (3.3-4) ... Setting up libssl-dev:amd64 (1.1.1f-1ubuntu2.10) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for install-info (6.7.0.dfsg.2-5) ... |
Hello, World!
1 2 3 4 5 |
rootlinks@Ubuntu20:~$ vi HelloWorld.py rootlinks@Ubuntu20:~$ cat HelloWorld.py print("Hello, World! (^^v") rootlinks@Ubuntu20:~$ python HelloWorld.py Hello, World! (^^v |