23
カジュアル Python 勉強会 1

カジュアル Python 勉強会 (2011/04/09)

  • Upload
    yono05

  • View
    611

  • Download
    2

Embed Size (px)

Citation preview

Page 1: カジュアル Python 勉強会 (2011/04/09)

カジュアル Python 勉強会

1

Page 2: カジュアル Python 勉強会 (2011/04/09)

自己紹介

2

• 小野裕作• 株式会社OCC所属• twitter id: yono

Page 3: カジュアル Python 勉強会 (2011/04/09)

今回の勉強会の目的

• Python 仲間を増やしたい•気軽に情報交換できる場がほしい•ネタは Python じゃなくても別にいい•場所と時間だけ決めて集まる方式

3

Page 4: カジュアル Python 勉強会 (2011/04/09)

おしながき

• Python 開発環境構築(Linux/Mac)• Python 基礎•その他

4

Page 5: カジュアル Python 勉強会 (2011/04/09)

手軽に環境構築するには• Mac• デフォルト: 2.6• MacPorts• homebrew

• Debian Squeeze• デフォルト: 無し• apt-get

• CentOS• デフォルト: 2.4

5

Page 6: カジュアル Python 勉強会 (2011/04/09)

Python 開発環境構築

• 複数バージョン管理 + 仮想パッケージ環境管理• Ruby でいうところの rvm• 依存性とか気にせずいろいろ試せる• 問題点• 準備が手間• うまく動かない場合あり

6

Page 7: カジュアル Python 勉強会 (2011/04/09)

Python 開発環境構築

7

pythonbrew

Python 2.5 Python 2.7 Python 3.2

Page 8: カジュアル Python 勉強会 (2011/04/09)

Python 開発環境構築

8

pythonbrew

Python 2.5 Python 2.7 Python 3.2

Django 1.0 Django 1.3

Page 9: カジュアル Python 勉強会 (2011/04/09)

Python 開発環境構築

9

pythonbrew

Python 2.5 Python 2.7 Python 3.2

virtualenvwrapper

Django 1.0 Django 1.3

Page 10: カジュアル Python 勉強会 (2011/04/09)

Python 開発環境構築

10

pythonbrew

Python 2.5 Python 2.7 Python 3.2

virtualenvwrapper

Django 1.0 Django 1.3

virtualenvwrapper

Django 1.3

on ver 2.5

Page 11: カジュアル Python 勉強会 (2011/04/09)

Python 開発環境構築

11

•Mac• python_select (MacPorts)• virtualenvwrapper• Linux• pythonbrew• virtualenvwrapper

Page 12: カジュアル Python 勉強会 (2011/04/09)

MacPorts• 公式サイトからインストーラをダウンロード&インストール

• Python 各バージョンをインストール

12

% sudo port install python_select % sudo port install python25 % sudo port install python27 % sudo port install python31

• 公式サイトからインストーラをダウンロード&インストール

% python_select -l Available versions: current none python25 python26-apple python27 \ python31

Page 13: カジュアル Python 勉強会 (2011/04/09)

MacPorts• バージョンを切り替える

13

% sudo python_select python25 Password: Selecting version "python25" for python

• PATH に追加

PATH=$PATH:/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin

• バージョン確認

% python_select -s python25

Page 14: カジュアル Python 勉強会 (2011/04/09)

pythonbrew• 必要なパッケージをインストール (CentOS)

14

# yum install gcc make curl zlib-devel wget# yum install openssl-devel gdbm-devel bzip2-devel# yum install readline-devel tcl-devel db4-devel# yum install tk-devel

• 必要なパッケージをインストール (Debian Squeeze)

# aptitude install build-essential python wget curl# aptitude install zlib1g-dev libdb-dev libgdbm-dev# aptitude install libbz2-dev libreadline-dev# aptitude install libssl-dev tcl-dev tk-dev

Page 15: カジュアル Python 勉強会 (2011/04/09)

pythonbrew• pythonbrew インストール

15

• pythonbrew を有効化% vi ̃/.bashrc

if [ -f $HOME/.pythonbrew/etc/bashrc ]; then source $HOME/.pythonbrew/etc/bashrcfi

% source ̃/.bashrc

% wget http://github.com/utahta/pythonbrew/raw/master/pythonbrew-install --no-check-certificate% chmod +x pythonbrew-install% ./pythonbrew-install

Page 16: カジュアル Python 勉強会 (2011/04/09)

pythonbrew• python 2.7.1 をインストール

16

• 2.7.1 を使用する

% pythonbrew switch 2.7.1

% pythonbrew install 2.7.1 [--force]

• インストール済みのバージョンを表示

% pythonbrew list

• 使用可能なコマンド確認

% pythonbrew help

Page 17: カジュアル Python 勉強会 (2011/04/09)

Python 開発環境構築

17

pythonbrew

Python 2.5 Python 2.7 Python 3.2

Page 18: カジュアル Python 勉強会 (2011/04/09)

pip• Python ライブラリ管理ツール• CPAN や gem と同等

• easy_install の代替• 存在するか確認し、無い場合はインストール

18

% [sudo] easy_install pip

Page 19: カジュアル Python 勉強会 (2011/04/09)

virtualenvwrapper• virtualenv を便利に使うためのツール• ライブラリをインストールするディレクトリを切り替えることが可能

19

% pip install virtualenv virtualenvwrapper

% mkdir ̃/.virtualenvs

• virtualenvwrapper が使用するディレクトリを用意

Page 20: カジュアル Python 勉強会 (2011/04/09)

virtualenvwrapper• シェルに設定記述

20

% vi ̃/.bashrc

export WORKON_HOME=$HOME/.virtualenvs

# pythonbrewVENV_SH=$HOME/.pythonbrew/pythons/Python-?.?.?/bin/virtualenvwrapper.sh# MacPortsVENV_SH=/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin/virtualenvwrapper.sh

if [ -f $VENV_SH ]; then source $VENV_SHfi

Page 21: カジュアル Python 勉強会 (2011/04/09)

virtualenvwrapper• ディレクトリ作成

21

% mkvirtualenv 2.5.5

% workon

• ディレクトリ切り替え

% workon 2.5.5

• ディレクトリ一覧

% deactivate

• virtualenv 無効化

Page 22: カジュアル Python 勉強会 (2011/04/09)

運用について

• バージョンごとにデフォルトのディレクトリを作る• 常に virtualenv を有効化• .bashrc に workon DEFAULT を書いておく例: 2.6.6 をデフォルトにする場合

22

workon 2.6.6

Page 23: カジュアル Python 勉強会 (2011/04/09)

Python 開発環境構築

23

pythonbrew

Python 2.5 Python 2.7 Python 3.2

virtualenvwrapper

Django 1.0 Django 1.3

virtualenvwrapper

Django 1.3

on ver 2.5