LoginSignup
3
3

More than 5 years have passed since last update.

pyenv-vertualenvでpython3系がうまくインストールできない

Posted at

前回の記事で整えた環境を使い続けて約1年半.

pyenv-vertualenvを使って,pythonの3系がうまくインストールできない問題にちょいちょい直面したので,対応した方法を記述しておく.

pyenvのバージョンアップがうまくいかない

Python3.5.2を利用しようとした時に発生したエラー.
pyenvのバージョン自体が古くて,Python3.5.2自体がpyenv内に存在しないため発生するエラー.

test_py352 $ pwd            # 作業していたディレクトリ
/Users/XXX/work/test_py352

test $ pyenv install 3.5.2
python-build: definition not found: 3.5.2

See all available versions with `pyenv install --list'.

If the version you need is missing, try upgrading pyenv:

  brew update && brew upgrade pyenv

コマンドを打った後に出てくるメッセージに従って,Homebrewのアップデートと,pyenvのアップグレードを行えば解決.

test_py352 $ cd ~            # ホームディレクトリに移動
$ brew update
remote: Counting objects: 995, done.
remote: Compressing objects: 100% (885/885), done.
remote: Total 995 (delta 243), reused 488 (delta 88), pack-reused 0
Receiving objects: 100% (995/995), 908.3

... 以下略 ...

$ brew upgrade pyenv
==> Upgrading 1 outdated package, with result:
pyenv 20151222
==> Upgrading pyenv
==> Installing dependencies

... 以下略 ...

Homebrewのアップデートがうまくいかない

Homebrewをアップデートしようとした時に,発生したエラー.

$ brew update
Error: The /usr/local directory is not writable.
Even if this directory was writable when you installed Homebrew, other
software may change permissions on this directory. For example, upgrading
to OS X El Capitan has been known to do this. Some versions of the
"InstantOn" component of Airfoil or running Cocktail cleanup/optimizations
are known to do this as well.

You should probably change the ownership and permissions of /usr/local
back to your user account.
  sudo chown -R $(whoami):admin /usr/local

こちらは,コマンドを打った後に出てくるメッセージに従っても,エラーが解決しなかったため,こちらを参考にして解決した.*1

$ sudo chown -R $(whoami):admin /usr/local
Password:

$ cd $(brew --prefix) && git fetch origin && git reset --hard origin/master
remote: Counting objects: 18655, done.
remote: Total 18655 (delta 7759), reused 7759 (delta 7759), pack-reused 10896
Receiving objects: 100% (18655/18655), 4.99 MiB

... 以下略 ...

local $ cd ~            # ホームディレクトリに移動
$ brew update
... 以下略 ...

brew update 後に権限をもとに戻すようメッセージが表示されるので,
メッセージに従いコマンドを実行

$ sudo chown root:wheel /usr/local
Password:

pyenv install 3.X.X するとBUILD FAILEDしちゃう

Python3系をpyenv使ってインストールしようとしたら発生したエラー.
Xcodeのコマンドラインツールがなくて発生するエラー.
OSX El Capitanで発生する模様.*2

test_py326 $ pwd            # 作業していたディレクトリ
/Users/XXX/work/test_py326

test_py326 $ pyenv install 3.2.6
Installing Python-3.2.6...
patching file ./Modules/readline.c
Hunk #1 succeeded at 225 (offset -6 lines).
Hunk #2 succeeded at 760 (offset -13 lines).
Hunk #3 succeeded at 813 (offset -13 lines).
Hunk #4 succeeded at 871 (offset -13 lines).
Hunk #5 succeeded at 919 with fuzz 2 (offset -24 lines).
patching file ./Lib/ssl.py
patching file ./Modules/_ssl.c
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
ERROR: The Python zlib extension was not compiled. Missing the zlib?

Please consult to the Wiki page to fix the problem.
https://github.com/yyuu/pyenv/wiki/Common-build-problems


BUILD FAILED (OS X 10.11.6 using python-build 20151028)

Inspect or clean up the working tree at /var/folders/z_/2dz9yyhd5_x_rczbsxcs_cdw0000gn/T/python-build.20161005151953.36759
Results logged to /var/folders/z_/2dz9yyhd5_x_rczbsxcs_cdw0000gn/T/python-build.20161005151953.36759.log

下記コマンドを実行し,ポップアップに従いXcodeコマンドラインツールを導入すれば解決.

$ xcode-select --install

もし,上記を実行してもPython3系をインストールできない場合は,もう一度pyenvをアップデートしてからpyenv installを実行するとうまくいく.

$ brew upgrade pyenv
... 以下略 ...

$ cd work/test_py326
test_py326 $ pyenv install 3.2.6
... 以下略 ...

なぜだかは,わからん٩( ᐛ )و

参考

  1. brew update error #49879
  2. 【Python3系対応】Mac(OSX EL Capitan)でpyenvで簡単にインストールして試す
  3. pyenvにおけるpythonインストールエラー対処法(BUILD FAILED)
3
3
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
3
3