@HeinrichM (天志 相川)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Pythonのバージョン切り替えができない

解決したいこと

Pythonを始めました。見よう見まねでいじっているのですが、そもそもバージョンが切り替えられていないことに気づきました。しかし一般的な方法ではうまく切り替わりません。(Mac, zsh)

ターミナルの表示

% pyenv versions                  
  system
* 3.10.0 (set by /Users/~

% pyenv global 3.10.0

% python3 --version
Python 3.10.0

% python --version
Python 2.7.16

全くの初心者です。どなたか方法の思い当たる方がいらっしゃったら優しくご教示いただきたいです。

0 likes

3Answer

macOS では python は常に Python 2.x を指します。 pyenv で2.xをインストールしない限り切り替わることはありません。 この回答は誤りでした。

0Like

pyenvの設定はマニュアル通りに済んでいるでしょうか?
https://github.com/pyenv/pyenv#installation

正しく設定していれば、pyenvを入れたディレクトリ以下のPythonにパスが通っているはずです。

# 私の場合は、README.mdの"Basic GitHub Checkout"の方法に則り、
# ~/.pyenv以下にpyenvを入れています。
# https://github.com/pyenv/pyenv#basic-github-checkout
% which python
/Users/user/.pyenv/shims/python
0Like

pyenv initと入力すると、下のように表示されます。

$ pyenv init                                                                                                                                           [ruby-2.6.3p62]

# (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 and ~/.zprofile:

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

# Load pyenv into the shell by adding
# the following to ~/.zshrc:

eval "$(pyenv init -)"

# Make sure to restart your entire logon session
# for changes to profile files to take effect.

ここに記載されているように、~/.profile、~/.zprofileの最後に

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

を追加してターミナルを再起動したらどうでしょうか。

0Like

Your answer might help someone💌