移行元で使っていたpython3の資産を、さくらのレンタルサーバーで使用したい。
2025年3月現在、さくらのレンタルサーバーでは標準でpython2しか使えないので、独自にpython3をインストールする。
前提
- さくらのレンタルサーバーのサポート情報(FAQ)を見ると、標準のpythonの使用を推奨していますが、独自にpython 3.12.9をインストールします。
- レンタルサーバーのスタンダードプランで提供されるFreeBSD 13.0-RELEASE(amd64)を使用します。
- python3のインストールにはopenssl 1.1.1以降が必要です。
標準で1.1.1(OpenSSL 1.1.1k-freebsd)がインストールされていますが、ライブラリがインストールされていないので、ビルドでエラーになります。…
To find the necessary bits, look in configure.ac and config.log.Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer - この問題を解決するために、先にOpenSSLをインストールします。また、pythonビルド時のエラーを回避するために LD_LIBRARY_PATH を指定します。
- root権限はないので、pythonやOpenSSLのインストール先は、ホームディレクトリ直下($HOME/local)にしています。
インストール手順
OpenSSL インストール手順
- OpenSSLのビルド
opensslからソースコードをダウンロードして、ビルド・インストールします。ここでopenssl 3.4を使用していますが、LTS版の3.0や3.5がお薦めです。12345678910mkdir ~/workcd ~/workwget --no-check-certificate https://www.openssl.org/source/openssl-3.4.0.tar.gztar xvfz openssl-3.4.0.tar.gzcd openssl-3.4.0./Configure --prefix=$HOME/localmakemake install - 環境変数LD_LIBRARY_PATH の追加
.bash_profile(または.bashrc)を開いて、環境変数PATH、LD_LIBRARY_PATH を編集し、読み直します。1234567vi ~/.bash_profile...PATH=$HOME/local/bin:$PATH...export LD_LIBRARY_PATH=$HOME/local/lib:$LD_LIBRARY_PATH...source ~/.bash_profile
python3 インストール手順
- python3のビルド
python3のソースコードをダウンロードし、ビルド・インストールします。
ここでは、python 3.12.9を使用しています。12345678910111213141516171819202122232425262728293031323334353637cd ~/workwget https://www.python.org/ftp/python/3.12.9/Python-3.12.9.tgztar xvfz Python-3.12.9.tgzcd Python-3.12.9./configure --prefix=$HOME/local --with-openssl=$HOME/local...checking for shm_unlink... yeschecking for include/openssl/ssl.h in /home/nextdoorwith/local... yeschecking whether compiling and linking against OpenSSL works... yeschecking for --with-openssl-rpath...checking whether OpenSSL provides required ssl module APIs... yeschecking whether OpenSSL provides required hashlib module APIs... yeschecking for --with-ssl-default-suites... pythonchecking for --with-builtin-hashlib-hashes... md5,sha1,sha2,sha3,blake2checking for libb2... nochecking for --disable-test-modules... yes...checking for stdlib extension module _lzma... yeschecking for stdlib extension module _ssl... yeschecking for stdlib extension module _hashlib... yeschecking for stdlib extension module _testcapi... yes...make...The necessary bits to build these optional modules were not found:_tkinterTo find the necessary bits, look in configure.ac and config.log.Checked 111 modules (31 built-in, ..., 0 disabled, 1 missing, 0 failed on import)make install...Processing /tmp/tmpb8swe3_5/pip-24.3.1-py3-none-any.whlInstalling collected packages: pipSuccessfully installed pip-24.3.1 - 既定のpythonコマンドを変更します。1234567891011which python/usr/local/bin/pythoncd ~/local/binln -s python3 pythonln -s pip3 pipwhich python/home/myuser/local/bin/pythonwhich pip/home/myuser/local/bin/pip