LoginSignup
0
0

More than 1 year has passed since last update.

Pythonをwsl2-Debianにインストールする

Last updated at Posted at 2022-08-10

Python3(ver. 3.10.6)をwsl2版Debian(ver. 11.3)にインストールした際、遭遇したエラーと対処です。言うほどエラーですかね?

最も簡潔と思しき道筋

  1. apt で依存関係のパッケージをインストール。パッケージはマニュアルにリストされている。
    https://devguide.python.org/getting-started/setup-building/index.html#build-dependencies
  2. パッケージをダウンロードして解凍し、./configureを実行した後、コンパイルしてインストールする。
$ ./configure --enable-optimizations --with-lto --with-ensurepip
$ make -j 8
$ sudo make install

make installだけsudoするのにこだわりはない。インストール先がユーザーローカルではなく、root権限でないと書けない場所なのでsudoで実行した。このような場合、本当ならrootになってmakemake installもすべきだと思う。もっとも後から気づいたので、ここは手間を惜しんだ。
3. (おまけ)matplotlibを入れる。

$ sudo pip3 install matplotlib

筆者が彷徨った過程

「Windows上のPythonで良くない?」とか言わない。Debianは勉強になる。だが面倒くさい。でも勉強になる。

参考

Python調達

Python公式から最新安定板のtarballをダウンロード。この時は、3.10.6でした。

wgetでも、windowsでダウンロードしてコピーでも良い。tar -xfで解凍。解凍した中身にREADME.rstがあるので読む。Build Instructionにシンプルな記述があるので、従う。./configureを実行するとMakefileを作ってくれるが、最後に"If you want..."というコメントが現れたため、それにも従う。真面目に--helpオプションを付けて動作を確認。結局、--enable-optimizations--with-lto、それから--with-ensurepipを付けて./configure

怒られた

The necessary bits to build these optional modules were not found:
_bz2                  _curses               _curses_panel      
_dbm                  _gdbm                 _tkinter           
readline                                                       
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  pwd                   time               


Failed to build these modules:
_ctypes

さーどうしましょ

参考にしようとしたサイトが対立しました。
最後の行を調べてみたらよくあるようで。sharedオプションがなかったのが原因?

"--enable-shared"を追加して再挑戦…してもダメでした

make cleanからのmake -j8。どや。やっぱりダメじゃん。ああああ面倒くさ。

エラー削れました

やっと根拠まで書かれたものを見つけた。公式マニュアルを丁寧に読むのとでは、どっちが早かっただろうか。

とりあえずsudo apt updateからのsudo apt upgradeをやっておいて…sudo apt install libffi-dev導入。ひとつエラーが削れた。

bits...の解消方法も見つけた。

まずはtk-dev。_tkinterを削れた。ん?setup.pyを見てね…?無視。全部sudo dpkg -l | grepで入ってないのを確認しながら進めて行く。
ncurses-dev。libgdbm-dev。libbz2-dev。libreadline-dev。

結果

The necessary bits to build these optional modules were not found:
_dbm                  readline                                 
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  pwd                   time               


Failed to build these modules:
_curses

cursesが失敗した?なんで?あとreadlineも消えてないぞ?なんで?と言いつつも、狙ったものは消えていたのでlibdb-devを入れる。libncurses"5"-devも入れました。

shared library関係なさそうだったんで一旦外して./configure試しましょう。通りますね。残るエラーはこれだけ。

The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  pwd                   time

…ん?readlineが消えてる?

Manual見てたら”Install dependencies"の項目があった。これ貼ればええんか。やだー。

$ sudo apt-get install build-essential gdb lcov pkg-config \
      libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \
      libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \
      lzma lzma-dev tk-dev uuid-dev zlib1g-dev

これを入れたら以下のとおり。

build-essential is already the newest version (12.9).
build-essential set to manually installed.
libbz2-dev is already the newest version (1.0.8-4).
libgdbm-dev is already the newest version (1.19-2).
libffi-dev is already the newest version (3.3-6).
libncurses5-dev is already the newest version (6.2+20201114-2).
libssl-dev is already the newest version (1.1.1n-0+deb11u3).
libssl-dev set to manually installed.
pkg-config is already the newest version (0.29.2-1).
pkg-config set to manually installed.
libreadline-dev is already the newest version (8.1-1).
libsqlite3-dev is already the newest version (3.34.1-3).
libsqlite3-dev set to manually installed.
tk-dev is already the newest version (8.6.11+1).
uuid-dev is already the newest version (2.36.1-8+deb11u1).
uuid-dev set to manually installed.
liblzma-dev is already the newest version (5.2.5-2.1~deb11u1).
liblzma-dev set to manually installed.
zlib1g-dev is already the newest version (1:1.2.11.dfsg-2+deb11u1).
The following additional packages will be installed:
  libbabeltrace1 libboost-regex1.74.0 libc6-dbg libcommon-sense-perl
  libdebuginfod1 libdw1 libgd-perl libipt2 libjson-perl libjson-xs-perl
  libmpdec3 libperlio-gzip-perl libpython3.9 libpython3.9-minimal
  libpython3.9-stdlib libsource-highlight-common libsource-highlight4v5
  libtypes-serialiser-perl media-types
Suggested packages:
  gdb-doc gdbserver
The following NEW packages will be installed:
  gdb lcov libbabeltrace1 libboost-regex1.74.0 libc6-dbg
  libcommon-sense-perl libdebuginfod1 libdw1 libgd-perl libgdbm-compat-dev
  libipt2 libjson-perl libjson-xs-perl libmpdec3 libperlio-gzip-perl
  libpython3.9 libpython3.9-minimal libpython3.9-stdlib
  libsource-highlight-common libsource-highlight4v5
  libtypes-serialiser-perl lzma lzma-dev media-types

結構入れてないのあったな。エラーメッセージからの推定だと大変だわ…。

結局消えなくて諦めた

The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  pwd                   time

おまけ

Debianのversionは$ cat /etc/debian_versionで確認。

make時に並列オプションを入れてます。4コアでHT入ってるので8スレッド。しかし本当に早くなるのかは疑問。下記の記事の通り。10年くらい前の経験だと、20%くらい速くなれば御の字…。

pyenvって入れて検索しようとしたらsuggestionで「pyenv 使うな」って出たのは少々驚き。

pyenvを使っているわけではなくて、必要なパッケージを導入するための情報としてpyenvのサイトを引いているページ。正しい使い方に思うけど、どうか。

というか

matplotlibを使いたいがためによくここまでやるわ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0