DRYな備忘録

Don't Repeat Yourself.

pyenv使ってみた:Python3.3.2環境構築

Goal

  • pyenvを使ってPython3.3.2環境構築

Log

# ここを参照
# http://qiita.com/la_luna_azul/items/3f64016feaad1722805c

% cd ~
% git clone git://github.com/yyuu/pyenv.git .pyenv

# """ .zshrc直接編集で事足ります """"
% echo 'export PYENV_ROOT="${HOME}/.pyenv"' >> ~/.zshrc
% echo 'if [ -d "${PYENV_ROOT}" ]; then' >> ~/.zshrc
% echo '    export PATH=${PYENV_ROOT}/bin:$PATH' >> ~/.zshrc
% echo '    eval "$(pyenv init -)"' >> ~/.zshrc
% echo 'fi' >> ~/.zshrc
# """ """

% exec $SHELL -l

ここで

~/.pyenv/libexec/../completions/pyenv.bash:16: command not found: complete

的なことを言われたら、

% echo '    eval "$(pyenv init -)"' >> ~/.zshrc

% echo '    eval "$(pyenv init - zsh)"' >> ~/.zshrc

とするとよいかも

% cd $PYENV_ROOT/plugins
% git clone git://github.com/yyuu/pyenv-virtualenv.git

#
# ---
#

% pyenv install 3.3.2
Downloading Python-3.3.2.tgz...
-> http://yyuu.github.io/pythons/0a2ea57f6184baf45b150aee53c0c8da
Installing Python-3.3.2...

BUILD FAILED

Inspect or clean up the working tree at /tmp/python-build.20130719081035.29492
Results logged to /tmp/python-build.20130719081035.29492.log

Last 10 log lines:
  File "<string>", line 2, in <module>
  File "/home/otiai10/.pyenv/versions/3.3.2/lib/python3.3/bz2.py", line 21, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ImportError: No module named '_bz2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 4, in <module>
ImportError: The Python bz2 extension was not compiled. Missing the bzip2 lib?

#
# お、おぅ...(; ・`д・´)
#

#
# ググった: http://stackoverflow.com/questions/812781/pythons-bz2-module-not-compiled-by-default
#

% apt-cache search bzip2
apsfilter - Magic print filter with automatic file type recognition
avfs - virtual filesystem to access archives, disk images, remote locations
bzip2-doc - high-quality block-sorting file compressor - documentation
bzip2 - high-quality block-sorting file compressor - utilities
lib64bz2-1.0 - high-quality block-sorting file compressor library - 64bit runtime
lib64bz2-dev - high-quality block-sorting file compressor library - 64bit development
libbz2-1.0 - high-quality block-sorting file compressor library - runtime
libbz2-dev - high-quality block-sorting file compressor library - development
libbz2-ocaml-dev - OCaml bindings for the bzip2 compression library
libbz2-ocaml - OCaml bindings for the bzip2 compression library
# 後略

# "bzip2" があるのでコレを入れてみる

% sudo apt-get install bzip2
Reading package lists... Done
Building dependency tree
Reading state information... Done
bzip2 is already the newest version.
The following packages were automatically installed and are no longer required:
  x11proto-xext-dev libgmp3-dev libglu1-mesa libxi-dev libxmu-headers mesa-common-dev libffi-dev alex libbsd-dev libgmpxx4ldbl happy libglu1-mesa-dev freeglut3-dev libxmu-dev
  libxext-dev libperl5.10 libgl1-mesa-dev freeglut3
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 49 not upgraded.
%

#
# ん、もともと入ってた?
# ためしにもう1回トライしてみる
# 

% pyenv install 3.3.2
Downloading Python-3.3.2.tgz...
-> http://yyuu.github.io/pythons/0a2ea57f6184baf45b150aee53c0c8da
Installing Python-3.3.2...

BUILD FAILED

Inspect or clean up the working tree at /tmp/python-build.20130719083537.4705
Results logged to /tmp/python-build.20130719083537.4705.log

Last 10 log lines:
  File "<string>", line 2, in <module>
  File "/home/otiai10/.pyenv/versions/3.3.2/lib/python3.3/bz2.py", line 21, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ImportError: No module named '_bz2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 4, in <module>
ImportError: The Python bz2 extension was not compiled. Missing the bzip2 lib?

#
# デスヨネー
#

% apt-cache search libbz2-dev
libbz2-dev - high-quality block-sorting file compressor library - development
%

#
# 今度はこれ試す
#

% sudo apt-get install libbz2-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  x11proto-xext-dev libgmp3-dev libglu1-mesa libxi-dev libxmu-headers mesa-common-dev libffi-dev alex libbsd-dev libgmpxx4ldbl happy libglu1-mesa-dev freeglut3-dev libxmu-dev
  libxext-dev libperl5.10 libgl1-mesa-dev freeglut3
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  libbz2-dev
0 upgraded, 1 newly installed, 0 to remove and 49 not upgraded.
Need to get 31.4 kB of archives.
After this operation, 111 kB of additional disk space will be used.
Get:1 http://ftp.jp.debian.org/debian/ squeeze/main libbz2-dev i386 1.0.5-6+squeeze1 [31.4 kB]
Fetched 31.4 kB in 0s (31.4 kB/s)
Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 33, in <module>
    from ALChacks import *
  File "/usr/share/apt-listchanges/ALChacks.py", line 32, in <module>
    sys.stderr.write(_("Can\'t set locale; make sure $LC_* and $LANG are correct!\n"))
NameError: name '_' is not defined
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "ja_JP.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously deselected package libbz2-dev.
(Reading database ... 74655 files and directories currently installed.)
Unpacking libbz2-dev (from .../libbz2-dev_1.0.5-6+squeeze1_i386.deb) ...
Setting up libbz2-dev (1.0.5-6+squeeze1) ...

#
# 入った
#
# もう一度 pyenv install
#

% pyenv install 3.3.2
Downloading Python-3.3.2.tgz...
-> http://yyuu.github.io/pythons/0a2ea57f6184baf45b150aee53c0c8da
Installing Python-3.3.2...
Installed Python-3.3.2 to /home/otiai10/.pyenv/versions/3.3.2

Downloading setuptools-0.9.5.tar.gz...
-> https://pypi.python.org/packages/source/s/setuptools/setuptools-0.9.5.tar.gz
Installing setuptools-0.9.5...
Installed setuptools-0.9.5 to /home/otiai10/.pyenv/versions/3.3.2

Downloading pip-1.3.1.tar.gz...
-> http://yyuu.github.io/pythons/cbb27a191cebc58997c4da8513863153
Installing pip-1.3.1...
Installed pip-1.3.1 to /home/otiai10/.pyenv/versions/3.3.2

%

#
# いったっぽい
#

#
# 確認
#

% cd
% python --version
Python 2.6.6
%
% cd prj/python/hisyotan
% python --version
Python 2.6.6
%
% pwd
/home/otiai10/prj/python/hisyotan
% pyenv local 3.3.2
% python --version
Python 3.3.2

# おお!

% cd
% python --version
Python 2.6.6
%

#
# おおお!!
# 

ディレクトリごとにPythonのバージョンが分けられている!すごい!

f:id:otiai10:20130719095114j:plain