LoginSignup
0
0

asdf Install

asdf で Python 環境を作るときのメモ.

asdfとは

1. asdf Install

1. Git から Clone

sudo apt install curl git ;\
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3

2. Path を通す

~/.bashrcは適宜読み替えること

echo -e ". "$HOME/.asdf/asdf.sh"" >> ~/.bashrc ;\
source .bashrc

2. python plugin Install

0. 念のためアプデ

asdf のプラグインの中から Python という名称のものを検索

asdf update ;\
asdf plugin list all | grep python

1. python のプラグイン追加

実際に追加されていることを確認

asdf plugin add python ;\
asdf plugin list
...

3. python Insatall

ここでBUILD FAILEDが発生する可能性があるが,詳細と対応は後述

0. インストール可能なバージョンのリストを表示

asdf list all python
$ asdf list all python 3.11
3.11.0
3.11-dev
3.11.1
3.11.2
3.11.3

1. お気に入りのVersionをインストールする

asdf install python 3.11.3

2. 環境に設定する

asdf global python 3.11.3

なお,引数を local にするとカレントディレクトリのみに適用できる.

asdf local python 3.8.10

3. 確認諸々

$ asdf list
python
  3.11.3
$ python --version
Python 3.11.3
$ which python
/home/User/.asdf/shims/python
$ pip --version
pip 22.3.1 from /home/User/.asdf/installs/python/3.11.3/lib/python3.11/site-packages/pip (python 3.11)
$

asdf と pyenv の比較

同様の機能を持つpyenvと比較しても,同じ機能が提供されていることがわかる.

$ asdf list all python | grep 3.11
3.11.0
3.11-dev
3.11.1
3.11.2
3.11.3
miniconda3-4.3.11
pypy2.7-7.3.11-src
pypy2.7-7.3.11
pypy3.8-7.3.11-src
pypy3.8-7.3.11
pypy3.9-7.3.11-src
pypy3.9-7.3.11
$
$ pyenv install --list | grep 3.11
  3.11.0
  3.11-dev
  3.11.1
  3.11.2
  3.11.3
  miniconda3-4.3.11
  pypy2.7-7.3.11-src
  pypy2.7-7.3.11
  pypy3.8-7.3.11-src
  pypy3.8-7.3.11
  pypy3.9-7.3.11-src
  pypy3.9-7.3.11
$

Error

build-error(1)

まっさらUbuntuででるエラーらしい.

$ asdf install python 3.11.3
python-build 3.11.3 /home/User/.asdf/installs/python/3.11.3
Downloading Python-3.11.3.tar.xz...
-> https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz
Installing Python-3.11.3...

BUILD FAILED (Ubuntu 22.04 using python-build 2.3.18)

Inspect or clean up the working tree at /tmp/python-build.20230526110831.10891
Results logged to /tmp/python-build.20230526110831.10891.log

Last 10 log lines:
checking for pkg-config... no
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/python-build.20230526110831.10891/Python-3.11.3':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
$

解決策

基本的なツールが足りないということなので,

sudo apt install build-essential

をすると解決する.

しかし,他にも足りないものがあるので,後述のエラーが後続する可能性もある.

build-error(2)

上述で足りないパッケージがあるときにでるエラーのよう.

$ asdf install python 3.11.3
python-build 3.11.3 /home/User/.asdf/installs/python/3.11.3
Downloading Python-3.11.3.tar.xz...
-> https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz
Installing Python-3.11.3...

BUILD FAILED (Ubuntu 22.04 using python-build 2.3.18)

Inspect or clean up the working tree at /tmp/python-build.20230526113233.650
Results logged to /tmp/python-build.20230526113233.650.log

Last 10 log lines:
  File "/tmp/python-build.20230526113233.650/Python-3.11.3/Lib/ensurepip/__init__.py", line 202, in _bootstrap
    return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/python-build.20230526113233.650/Python-3.11.3/Lib/ensurepip/__init__.py", line 103, in _run_pip
    return subprocess.run(cmd, check=True).returncode
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/python-build.20230526113233.650/Python-3.11.3/Lib/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/tmp/python-build.20230526113233.650/Python-3.11.3/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmp17aexia7/setuptools-65.5.0-py3-none-any.whl\', \'/tmp/tmp17aexia7/pip-22.3.1-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmp17aexia7\', \'--root\', \'/\', \'--upgrade\', \'setuptools\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
make: *** [Makefile:1860: install] Error 1
$

解決策

何を求められているかよくわかってないが pyenv と同じ環境を用意しておけば問題ないのではなかろうか,ということで GitHub/pyenv - wiki を参照.

sudo apt update; sudo apt -y install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

感想

anyenv > pyenv よりも asdf の方がいい.個人的にjavaの環境マネージャを anyenv > jenv にしていたが, jenv は asdf のようにインストールする機能はなく,インストールしたものを登録する形式なので.
でも,Python環境を構築するにあたって,WSLのような仮想環境ではなく,メイン環境を使いたいときがある(個人的にはUSB周りやEthernet周りなどの設定の問題や貸与環境など).
私物PCであれば Windows なら WSL で asdf を,それ以外では Terminal から asdf を使用したい.
Windows に環境を作るとなると, pyenv のみコマンドラインから導入かなぁ…と.

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