ターミナルを開いたら変な文字が…
今日、ターミナルを開いたら、突然以下のメッセージが表示された。。
$ python -VするとPython 2.7.10が出力結果に出る。
Python3系が使えなくなった…!!!
実行環境と状況
macOS Mojave
* ターミナルはzshではなく、bashです。
python2.7とpython3.7が入っていて、npmのパッケージで一部python2系が必要だったので、完全に3系に移行はできない状態ということもあり、これまでいじり倒しすぎてpython環境がわけわからないことになっていたので、Anaconda消したり最近整理中で迷走中です。
とりあえずpyenvが使えないと切り替えができないので困ったという状況でした。
試したこと
エラーメッセージに書いている通り$ pyenv -initしてみる
訳がわからない…
とりあえずエラーメッセージで促された通り、 $ pyenv -initをターミナルへ入力してみた。
出力内容はこんな感じ。
$ pyenv init
# (The below instructions are intended for common
# shell setups. See the README for more guidance
# if they don't apply and/or don't work for you.)
# Add pyenv executable to PATH and
# enable shims by adding the following
# to ~/.profile:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
# If your ~/.profile sources ~/.bashrc,
# the lines need to be inserted before the part
# that does that. See the README for another option.
# If you have ~/.bash_profile, make sure that it
# also executes the above lines -- e.g. by
# copying them there or by sourcing ~/.profile
# Load pyenv into the shell by adding
# the following to ~/.bashrc:
eval "$(pyenv init -)"
# Make sure to restart your entire logon session
# for changes to profile files to take effect.
すすめられるままにREAD MEを読んでみる
shell setups. See the README for more guidanceと、オススメされていたので、読んでみる。
README.md
いざ入力してみる
私は.bashrcというファイルも、.profileというファイルもホームにない。あるのは.bash_profileだけ。
.bash_profileへ書いてみたが、なんか状態は変わらず。。
そのため、今度は.profileに以下を入力してみた。
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
$ echo 'eval "$(pyenv init --path)"' >> ~/.profile
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.profile
最後に以下のコマンドで、入力内容を反映させた。
$ source .profile
そしたら無事?に$ python -VしたらPython 3.7.5の出力結果が!
おかえり!
.bash_profileとか.profileとかわからないので調べてみようと思った。
↧