2. Unix プラットフォームで Python を使う¶
2.1. 最新バージョンの Python の取得とインストール¶
2.1.1. Linux¶
Python comes preinstalled on most Linux distributions, and is available as a package on all others. However there are certain features you might want to use that are not available on your distro's package. You can compile the latest version of Python from source.
In the event that the latest version of Python doesn't come preinstalled and isn't in the repositories as well, you can make packages for your own distro. Have a look at the following links:
参考
- https://www.debian.org/doc/manuals/maint-guide/first.en.html
- Debian ユーザー向け 
- https://en.opensuse.org/Portal:Packaging
- OpenSuse ユーザー向け 
- https://docs.fedoraproject.org/en-US/package-maintainers/Packaging_Tutorial_GNU_Hello/
- Fedora ユーザー向け 
- https://slackbook.org/html/package-management-making-packages.html
- Slackware ユーザー向け 
2.1.1.1. Installing IDLE¶
In some cases, IDLE might not be included in your Python installation.
- For Debian and Ubuntu users: - sudo apt update sudo apt install idle 
- For Fedora, RHEL, and CentOS users: - sudo dnf install python3-idle 
- For SUSE and OpenSUSE users: - sudo zypper install python3-idle 
- For Alpine Linux users: - sudo apk add python3-idle 
2.1.2. FreeBSD と OpenBSD¶
- FreeBSD ユーザーが Python パッケージを追加するには次のようにしてください: - pkg install python3 
- OpenBSD ユーザーが Python パッケージを追加するには次のようにしてください: - pkg_add -r python pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz - 例えば、i386 ユーザーが Python 2.5.1 を取得するには次のようにします: - pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz
2.2. Python のビルド¶
CPython を自分でコンパイルしたい場合は、まず ソース を入手します。 最新リリース版のソースをダウンロード、あるいはソースリポジトリから新しく クローン を作成してください。(パッチの作成に貢献したい場合はクローンが必要になるでしょう。)
ビルド手順は通常のコマンドで行います
./configure
make
make install
Configure のオプション や特定の Unix プラットフォームにおける注意点は Python ソースツリーのルートにある README.rst に細かく記載されています。
警告
make install は python3 バイナリを上書きまたはリンクを破壊してしまうかもしれません。そのため、make install の代わりに exec_prefix/bin/pythonversion のみインストールする make altinstall が推奨されています。
2.4. その他¶
Python スクリプトを Unix で簡単に使うためには、例えば次のようにしてスクリプトを実行可能ファイルにし、
$ chmod +x script
適切な shebang 行をスクリプトの先頭に置きます。たいていの場合良い方法は
#!/usr/bin/env python3
で、PATH 全体から Python インタープリターを探します。しかし、いくつかの Unix は env コマンドを持たないので、インタープリターのパスを /usr/bin/python3 のようにハードコードしなければならないかもしれません。
シェルコマンドを Python スクリプトから使うには、 subprocess モジュールを参照してください。
2.5. Custom OpenSSL¶
- To use your vendor's OpenSSL configuration and system trust store, locate the directory with - openssl.cnffile or symlink in- /etc. On most distribution the file is either in- /etc/sslor- /etc/pki/tls. The directory should also contain a- cert.pemfile and/or a- certsdirectory.- $ find /etc/ -name openssl.cnf -printf "%h\n" /etc/ssl 
- Download, build, and install OpenSSL. Make sure you use - install_swand not- install. The- install_swtarget does not override- openssl.cnf.- $ curl -O https://www.openssl.org/source/openssl-VERSION.tar.gz $ tar xzf openssl-VERSION $ pushd openssl-VERSION $ ./config \ --prefix=/usr/local/custom-openssl \ --libdir=lib \ --openssldir=/etc/ssl $ make -j1 depend $ make -j8 $ make install_sw $ popd 
- Build Python with custom OpenSSL (see the configure - --with-openssland- --with-openssl-rpathoptions)- $ pushd python-3.x.x $ ./configure -C \ --with-openssl=/usr/local/custom-openssl \ --with-openssl-rpath=auto \ --prefix=/usr/local/python-3.x.x $ make -j8 $ make altinstall 
注釈
Patch releases of OpenSSL have a backwards compatible ABI. You don't need to recompile Python to update OpenSSL. It's sufficient to replace the custom OpenSSL installation with a newer version.