====== pythonbrew の使い方 ====== ===== インストール (Linux & Mac編) ===== Linux の場合は python のビルドに必要なパッケージをインストールする。\\ \\ CentOS 7.1.1503 $ sudo yum install yum-utils $ mkdir ~/work $ cd ~/work $ curl -O http://vault.centos.org/centos/7.1.1503/os/Source/SPackages/python-2.7.5-16.el7.src.rpm $ sudo yum-builddep ~/work/python-2.7.5-16.el7.src.rpm \\ Fedora $ sudo dnf install yum-utils $ mkdir ~/work $ cd ~/work $ curl -O http://ftp.yz.yamagata-u.ac.jp/pub/Linux/fedora/linux/releases/27/Workstation/source/tree/Packages/p/python2-2.7.13-17.fc27.src.rpm $ sudo yum-builddep ~/work/python2-2.7.13-17.fc27.src.rpm \\ CentOS $ sudo yum install gcc bzip2-devel db4-devel expat-devel glibc-devel gmp-devel \ gdbm-devel libffi-devel libGL-devel libX11-devel ncurses-devel openssl-devel \ readline-devel sqlite-devel tcl-devel tix-devel tk-devel zlib-devel ※python-2.6.6-52.el6.src.rpm の python.spec より\\ \\ Ubuntu $ sudo apt-get install zlib1g-dev bzip2 libbz2-dev libreadline6-dev libjpeg62 \ libjpeg62-dev libsqlite3-0 libsqlite3-dev libgdbm3 libgdbm-dev libssl0.9.8 \ libssl-dev tk8.4-dev tk8.5-dev pythonbrew をダウンロードする。 $ curl -kL http://xrl.us/pythonbrewinstall | bash .bashrc に以下の記述を追加する。 $ vi ~/.bashrc [[ -s "$HOME/.pythonbrew/etc/bashrc" ]] && source "$HOME/.pythonbrew/etc/bashrc" .bashrc の設定を反映させる。 $ source ~/.bashrc pythonbrew の動作確認を行う。 $ pybrew version 1.3.6 ===== 使い方 ===== ^ Pythonbrew 関連 ^^ ^コマンド ^説明 ^ | pybrew update | pythonbrew を latest version にアップデートする。 | ^ Python 環境関連 ^^ ^コマンド ^説明 ^ | pybrew install 2.7.10 | 指定されたバージョンの python をビルドしてインストールする。 | | pybrew list | インストール済みの python を一覧表示する。 | | pybrew switch 2.7.10 | 指定されたバージョンの python を使用するように切り替えを行う。 | | pybrew uninstall 2.7.10 | 指定されたバージョンの python をアンインストールする。 | ^ 仮想環境関連 ^^ ^コマンド ^説明 ^ | pybrew venv create project_name | 指定された project_name の仮想環境を作成する。 | | pybrew venv list | 作成済みの仮想環境を一覧表示する。 | | pybrew venv use project_name | 指定された project_name の仮想環境を使用するように切り替えを行う。 | | pybrew venv delete project_name | 指定された project_name の仮想環境を削除する。 | ==== python 2.7.10 のインストールの例 ==== $ pybrew install 2.7.10 Use the previously fetched /home/tomoyan/.pythonbrew/dists/Python-2.7.10.tgz Extracting Python-2.7.10.tgz into /home/tomoyan/.pythonbrew/build/Python-2.7.10 This could take a while. You can run the following command on another shell to track the status: tail -f "/home/tomoyan/.pythonbrew/log/build.log" Installing Python-2.7.10 into /home/tomoyan/.pythonbrew/pythons/Python-2.7.10 Downloading ez_setup.py as /home/tomoyan/.pythonbrew/dists/ez_setup.py ######################################################################## 100.0% Installing distribute into /home/tomoyan/.pythonbrew/pythons/Python-2.7.10 Installing pip into /home/tomoyan/.pythonbrew/pythons/Python-2.7.10 Installed Python-2.7.10 successfully. Run the following command to switch to Python-2.7.10. pythonbrew switch 2.7.10 [tomoyan@emisia-sv work]$ pybrew switch 2.7.10 ==== python 3.4.3 のインストールの例 ==== $ pybrew install 3.4.3 Downloading Python-3.4.3.tgz as /home/tomoyan/.pythonbrew/dists/Python-3.4.3.tgz ######################################################################## 100.0% Extracting Python-3.4.3.tgz into /home/tomoyan/.pythonbrew/build/Python-3.4.3 This could take a while. You can run the following command on another shell to track the status: tail -f "/home/tomoyan/.pythonbrew/log/build.log" Installing Python-3.4.3 into /home/tomoyan/.pythonbrew/pythons/Python-3.4.3 Downloading ez_setup.py as /home/tomoyan/.pythonbrew/dists/ez_setup.py ######################################################################## 100.0% Installing distribute into /home/tomoyan/.pythonbrew/pythons/Python-3.4.3 Installing pip into /home/tomoyan/.pythonbrew/pythons/Python-3.4.3 Installed Python-3.4.3 successfully. Run the following command to switch to Python-3.4.3. pythonbrew switch 3.4.3 ==== python のバージョンを指定して仮想環境を作成する例 ==== $ pybrew venv create py33dj15 -p 3.3.0 Downloading virtualenv.tar.gz as /home/tomoyan/.pythonbrew/dists/virtualenv.tar.gz ######################################################################## 100.0% Extracting virtualenv into /home/tomoyan/.pythonbrew/etc/virtualenv Downloading virtualenv-clone.tar.gz as /home/tomoyan/.pythonbrew/dists/virtualenv-clone.tar.gz ######################################################################## 100.0% Extracting virtualenv-clone into /home/tomoyan/.pythonbrew/etc/virtualenv-clone Creating `py33dj15` environment into /home/tomoyan/.pythonbrew/venvs/Python-3.3.0 Already using interpreter /home/tomoyan/.pythonbrew/pythons/Python-3.3.0/bin/python Using base prefix '/home/tomoyan/.pythonbrew/pythons/Python-3.3.0' New python executable in /home/tomoyan/.pythonbrew/venvs/Python-3.3.0/py33dj15/bin/python Installing distribute...........done. Installing pip..........done. 作成された仮想環境の確認 $ pybrew venv list Python-3.3.0 py33dj15 ==== 仮想環境の切り替え ==== $ pybrew venv use py33dj15 # Using `py33dj15` environment (found in /home/tomoyan/.pythonbrew/venvs/Python-3.3.0) # To leave an environment, simply run `deactivate` (py33dj15)$ ==== 仮想環境の削除 ==== $ pybrew venv delete py33dj15 -p 3.3.0 Deleting `py33dj15` environment in /home/tomoyan/.pythonbrew/venvs/Python-3.3.0 ===== pythonbrew の config に書かれていない新しい Python をインストールする方法 ===== - config.cfg を直す。 $ vi ~/.pythonbrew/etc/config.cfg 最終に書き足す。(x.x.x はバージョンを記述)\\ url はこちらを調べると分かります。http://www.python.org/ftp/python/ [Python-x.x.x] url = http://www.python.org/ftp/python/x.x.x/Python-x.x.x.tgz latest = True 記述例 [Python-2.7.8] url = http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz [Python-2.7.9] url = http://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz [Python-2.7.10] url = http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz latest = True [Python-3.4.1] url = http://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz [Python-3.4.2] url = http://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz [Python-3.4.3] url = http://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz latest = True - python をインストールする。 $ pybrew install x.x.x Downloading Python-x.x.x.tgz as /Users/tomoyan/.pythonbrew/dists/Python-x.x.x.tgz ######################################################################## 100.0% Extracting Python-x.x.x.tgz into /Users/tomoyan/.pythonbrew/build/Python-x.x.x This could take a while. You can run the following command on another shell to track the status: tail -f "/Users/tomoyan/.pythonbrew/log/build.log" Installing Python-x.x.x into /Users/tomoyan/.pythonbrew/pythons/Python-x.x.x Downloading distribute_setup.py as /Users/tomoyan/.pythonbrew/dists/distribute_setup.py ######################################################################## 100.0% Installing distribute into /Users/tomoyan/.pythonbrew/pythons/Python-x.x.x Installing pip into /Users/tomoyan/.pythonbrew/pythons/Python-x.x.x Installed Python-x.x.x successfully. Run the following command to switch to Python-x.x.x. pythonbrew switch x.x.x - 動作を確認する。 $ pybrew switch x.x.x Switched to Python-x.x.x $ python -V Python x.x.x ===== メモ ===== pythonbrew は $HOME/.pythonbrew にインストールされる。\\ ビルドした python は pythons に Python-[バージョン]の形式で格納される。\\ venv create した python は venvs Python-[バージョン]/[環境名]の形式で格納される。\\ $ mkdir .pythonbrew/pythons/Python-2.7.13 $ mkdir .pythonbrew/venvs/Python-2.7.13 $ cd .pythonbrew/venvs/Python-2.7.13 $ virtualenv -p /usr/bin/python2.7 py27dj110 すると $ pybrew venv use py27dj110 できる。 ===== トラブルシューティング ===== ==== distribute インストールに失敗する ==== pybrew install x.x.xx の実行中に\\ **curl: (7) Failed connect to python-distribute.org:80; 接続がタイムアウトしました**\\ が表示される。\\ \\ [[http://pythonhosted.org/setuptools/merge.html|2013年に distribute は setuptools にマージされた]] ので、config.cfg を直す。\\ [[https://github.com/utahta/pythonbrew/pull/145|Update config.cfg #145]] - いちおう作者にプルリクエストしてみました。(^^;;)\\ $ vi ~/.pythonbrew/etc/config.cfg [distribute] #url = http://python-distribute.org/distribute_setup.py url = https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py python のインストール。 $ pybrew install 2.7.10 Use the previously fetched /home/tomoyan/.pythonbrew/dists/Python-2.7.10.tgz Extracting Python-2.7.10.tgz into /home/tomoyan/.pythonbrew/build/Python-2.7.10 This could take a while. You can run the following command on another shell to track the status: tail -f "/home/tomoyan/.pythonbrew/log/build.log" Installing Python-2.7.10 into /home/tomoyan/.pythonbrew/pythons/Python-2.7.10 Downloading ez_setup.py as /home/tomoyan/.pythonbrew/dists/ez_setup.py ######################################################################## 100.0% Installing distribute into /home/tomoyan/.pythonbrew/pythons/Python-2.7.10 Installing pip into /home/tomoyan/.pythonbrew/pythons/Python-2.7.10 Installed Python-2.7.10 successfully. Run the following command to switch to Python-2.7.10. pythonbrew switch 2.7.10 $ pybrew switch 2.7.10 Switched to Python-2.7.10 $ pip --version pip 7.0.1 from /home/tomoyan/.pythonbrew/pythons/Python-2.7.10/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg (python 2.7) ==== setuptools インストールに失敗する ==== ERROR: Failed to install setuptools. See /home/tomoyan/.pythonbrew/log/build.log to see why. Skip installation of setuptools. zlib-devel を入れてインストールし直す。(入れないと zlib モジュールが組み込まれない) $ sudo yum install zlib-devel $ pybrew uninstall x.x.x $ pybrew install x.x.x ===== 参考文献 ===== [[https://github.com/utahta/pythonbrew|utahta/pythonbrew · GitHub]]\\ [[http://www.ninxit.com/blog/2010/10/04/python%E3%81%AE%E3%83%90%E3%83%BC%E3%82%B8%E3%83%A7%E3%83%B3%E3%82%92%E7%AE%A1%E7%90%86%E3%81%99%E3%82%8B%E3%83%84%E3%83%BC%E3%83%AB%E3%80%81pythonbrew%E3%82%92%E4%BD%9C%E3%81%A3%E3%81%A6%E3%81%BF/|Pythonのバージョンを管理するツール、pythonbrewを作ってみた | ninxit.blog]]\\ [[http://toggtc.hatenablog.com/entry/2012/02/06/023652|Mac OS X 10.7.3 Lionでpythonbrew, virtualenv, pip, buildoutなPython環境を構築する 第2回 pythonbrewとPythonのインストール - A Way of Code]]\\ [[http://www.yunabe.jp/docs/python_package_management.html|Python パッケージ管理技術まとめ (pip, setuptools, easy_install, etc)]]\\ [[https://github.com/utahta/pythonbrew/blob/master/pythonbrew/installer/pythoninstaller.py|pythonbrew/pythoninstaller.py at master · utahta/pythonbrew · GitHub]]\\