Skip to content

Latest commit

 

History

History
executable file
·
303 lines (252 loc) · 10.4 KB

PythonSetUp_asdf.md

File metadata and controls

executable file
·
303 lines (252 loc) · 10.4 KB

asdf Install

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
  1. Path を通す
echo -e ". "$HOME/.asdf/asdf.sh"" >> ~/.bashrc ;\
source .bashrc
$ sudo apt install curl git
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
curl is already the newest version (7.81.0-1ubuntu1.10).
curl set to manually installed.
git is already the newest version (1:2.34.1-1ubuntu1.9).
git set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3
Cloning into '/home/take/.asdf'...
remote: Enumerating objects: 8323, done.
remote: Counting objects: 100% (186/186), done.
remote: Compressing objects: 100% (108/108), done.
Receiving objects: 100% (8323/8323), done.
Resolving deltas: 100% (4944/4944), done.
Note: switching to '0adc6c11fb4f87dbb476f8b61e4cf8fb7613599b'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

$ echo -e ". "$HOME/.asdf/asdf.sh"" >> ~/.bashrc
$ source .bashrc
$ asdf --version
v0.11.3-0adc6c1
$

2. python plugin Install

  1. 念のためアプデ,asdf のプラグインの中から Python という名称のものを検索
asdf update ;\
asdf plugin list all | grep python
  1. python のプラグインを追加し,実際に追加されていることを確認
asdf plugin add python ;\
asdf plugin list
$ asdf plugin list all | grep python
Cloning into '/home/take/.asdf/repository'...
remote: Enumerating objects: 5187, done.
remote: Counting objects: 100% (5187/5187), done.
remote: Compressing objects: 100% (2359/2359), done.
Receiving objects: 100% (5187/5187), done.
Resolving deltas: 100% (2802/2802), done.
Updating files: 100% (678/678), done.
python                        https://github.com/danhper/asdf-python.git
$ asdf update
HEAD is now at 0adc6c1 chore(master): release 0.11.3 (#1498)Updated asdf to release v0.11.3
$ asdf plugin add python
$ asdf plugin list
python
$

Compare with pyenv

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

$ asdf list all python 3.11
3.11.0
3.11-dev
3.11.1
3.11.2
3.11.3
$ 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
$

3. python Insatall

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

  1. お気に入りのVersionをインストールする
asdf install python 3.11.3
$ asdf install python 3.11.3
python-build 3.11.3 /home/take/.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...
Installed Python-3.11.3 to /home/take/.asdf/installs/python/3.11.3
  1. 環境に設定する
asdf global python 3.11.3

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

asdf local python 3.8.10
  1. 確認諸々
$ asdf list
python
  3.11.3
$ python --version
Python 3.11.3
$ which python
/home/take/.asdf/shims/python
$ pip --version
pip 22.3.1 from /home/take/.asdf/installs/python/3.11.3/lib/python3.11/site-packages/pip (python 3.11)
$

Error

build-error(1)

見たことあるエラーが出た.まっさらUbuntuででるそうな.

$ asdf install python 3.11.3
python-build 3.11.3 /home/take/.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)

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

$ asdf install python 3.11.3
python-build 3.11.3 /home/take/.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
$

解決策

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