0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Catalina: zsh への移行でpyenvが動かなくなる問題

Posted at

問題

CatalinaにOSをアップデートするとbashからzshへの移行を勧められる。ここで、zshに移ってしまうとそのままではpyenvが機能しない。

環境

  • iMac late2012
  • macOS Catalina 10.15.2

再現してみる

pyenvでversionを表示させると確かに出てくる。

% pyenv versions
  system
  3.6.5
  3.6.5/envs/3.6.5_tensorflow_cpu
  3.6.5_tensorflow_cpu
* 3.7.4

現在設定されているpython環境は3.7.4なはず。

% pyenv local
3.7.4

しかし、実行すると、systemのpythonが上がってくる。

% python

WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Nov  9 2019, 05:55:08)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
Type "help", "copyright", "credits" or "license" for more information.exit

解決策

sh で使用する場合には、.zshenv や .zshrc などに設定を書く必要がある。

以下の行を追加してあげることでpyenvが復活する。

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

エディタで.zshrcを起動して、

vim ~/.zshrc

先ほどの行を足してあげる。そして、sourceして再読み込みすればオッケー

source ~/.zshrc

試しにPythonを起動してみる

% python
Python 3.7.4 (default, Sep 28 2019, 14:11:05)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

期待通りのpython環境が上がってきてくれました!!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?