4
4

More than 3 years have passed since last update.

anyenv+pyenvでの環境構築(pyenvのみから移行(Mac))

Last updated at Posted at 2020-08-14

書いてること

pyenvのみの環境からanyenv+pyenvの環境への変更方法
(pyenvのアンインストール、anyenv+pyenvのインストール)
目新しいことはない(自分用)

pyenv→anyenv+pyenv

結論、pyenvを削除してanyenvをインストール、anyenvでpyenvをインストールして、必要な環境を作り直す
こちらによると単純にフォルダ移動するだけだと問題が起こるようなことが書いてあったので削除して作り直すことにした。

pyenvでインストールしたものを確認して削除

% pyenv versions
% pyenv uninstall 削除するもの

続いてpyenvのアンインストール

% brew uninstall pyenv

.zprofileに以下のような3行の記述があると思うので削除もしくはコメントアウト(以下のようにコメントアウトした)

#export PYENV_ROOT="$HOME/.pyenv"
#export PATH="$PYENV_ROOT/bin:$PATH"
#eval "$(pyenv init -)" 

また、/User/ユーザー名/内に.pyenvという隠しフォルダがあるが、もういらないので削除しておく。(残ってても問題なはいがすっきりさせておこう)

anyenvのインストール

% brew install anyenv

.zprofileに以下を追記

% echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.zprofile
% echo 'eval "$(anyenv init -)"' >> ~/.zprofile

ターミナルの再起動すると以下のように言われるので

% source ~/.zprofile    
ANYENV_DEFINITION_ROOT(/Users/ユーザー名/.config/anyenv/anyenv-install) doesn't exist. You can initialize it by:
> anyenv install --init

指示に従う。

% anyenv install --init
Manifest directory doesn't exist: /Users/ユーザー名/.config/anyenv/anyenv-install
Do you want to checkout ? [y/N]: y
Cloning https://github.com/anyenv/anyenv-install.git master to /Users/ユーザー名/.config/anyenv/anyenv-install...
Cloning into '/Users/ユーザー名/.config/anyenv/anyenv-install'...
remote: Enumerating objects: 48, done.
remote: Total 48 (delta 0), reused 0 (delta 0), pack-reused 48
Receiving objects: 100% (48/48), 6.66 KiB | 3.33 MiB/s, done.
Resolving deltas: 100% (2/2), done.

Completed!

pyenvのインストール

% anyenv install pyenv
/var/folders/s5/67jvmwk14ss73fj1x4368sym0000gn/T/pyenv.20200815051616.35266 ~
Cloning https://github.com/pyenv/pyenv.git master to pyenv...
Cloning into 'pyenv'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 18140 (delta 0), reused 3 (delta 0), pack-reused 18133
Receiving objects: 100% (18140/18140), 3.62 MiB | 2.63 MiB/s, done.
Resolving deltas: 100% (12334/12334), done.
~

Install pyenv succeeded!
Please reload your profile (exec $SHELL -l) or open a new session. 

指示に従って以下のようにシェルを再起動
% exec $SHELL -l

pyenvの確認

% pyenv versions
* system (set by /Users/ユーザー名/.anyenv/envs/pyenv/version)

% pyenv install 3.7.8
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.8.tar.xz...
-> https://www.python.org/ftp/python/3.7.8/Python-3.7.8.tar.xz
Installing Python-3.7.8...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.7.8 to /Users/ユーザー名/.anyenv/envs/pyenv/versions/3.7.8

% pyenv global 3.7.8
% python
Python 3.7.8 (default, Aug 15 2020, 05:17:58) 
[Clang 11.0.3 (clang-1103.0.32.59)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

ちゃんと切り替わっている

参考

https://note.com/digiangler777/n/n16c2853e7287
https://qiita.com/kai_kou/items/f54931991a781b96bb9c
https://qiita.com/koooooo/items/b21d87ffe2b56d0c589b
https://stangler.hatenablog.com/entry/2019/01/18/161956

4
4
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
4
4