Upgrade to Pro — share decks privately, control downloads, hide ads and more …

python_virenv.pdf

 python_virenv.pdf

社内LTで発表した資料

18c5d6e2413dc02665fd4210bf5d094b?s=128

Satoshi Ohki

November 15, 2012
Tweet

More Decks by Satoshi Ohki

Other Decks in Programming

Transcript

  1. MacOSXͰ࡞Δ PythonԾ૝؀ڥ 2012/11/16 roothybrid7 12೥11݄17೔౔༵೔

  2. ։ൃ؀ڥߏங • స৬ͯ͠ॳΊͯͷ͓࢓ࣄ!! • Ұ೔͕͔Γ!? • େม? 12೥11݄17೔౔༵೔

  3. ͳΜ΋ߟ͑ͣ੔͑Δ • खॱؒҧ͑ͨʔ • ͍Βͳ͍ͷΞϯΠϯετʔϧͰ͖Ͷʔ • ؅ཧπʔϧಈ͔Ͷʔ 12೥11݄17೔౔༵೔

  4. Pythonͷ։ൃ؀ڥ • easy_installͱ͔pipͱ͔ɺsetuptoolsͱ ͔distributeͱ͔Կ͕ҧ͏ͷ? • ϓϩδΣΫτຖʹ࢖༻͢Δύοέʔδ͕ ҟͳΔͱ͖Կ࢖͑͹͍͍ͷ? 12೥11݄17೔౔༵೔

  5. ଞʹ΋ • όʔδϣϯΛҙࣝ͠ ͯɺίϚϯυ࣮ߦ͢Μ ͷΊΜͲ͍ • όʔδϣϯΞοϓͨ͠ ͍ͱ͖ɺҠߦΊΜͲ͍ • ؀ڥߏஙࣦഊͨ͠ͱ

    ͖ɺϦΧόϦ͕ΊΜͲ ͍ 12೥11݄17೔౔༵೔
  6. ࣦഊ͸ΏΔ͞ΕΜ! 12೥11݄17೔౔༵೔

  7. PythonΠϯετʔϧ • HomebrewͰΠϯετʔϧ͕͓͢͢Ί • brew tap homebrew/versions ͰϦϙδ τϦ௥Ճ͢ΔͱΠϯετʔϧՄೳͳόʔ δϣϯ͕૿͑Δ

    12೥11݄17೔౔༵೔
  8. Virtualenv • Ծ૝؀ڥΛ࡞ͬͯ͘ΕΔ • pip install virtualenv • Ծ૝؀ڥΛɺ؆୯ʹ௥Ճ࡟আ͕Մೳ •

    Ծ૝؀ڥ಺Ͱ͸ɺࢦఆͨ͠Pythonͷό ʔδϣϯͰಈ࡞͢ΔͷͰɺ͍͍ͪͪόʔ δϣϯΛҙࣝ͠ͳͯ͘Α͍ 12೥11݄17೔౔༵೔
  9. Virtualenvwrapper • ͱ͸͍͑ɺVirtualenv୯ମͩͱԾ૝؀ڥ ΛͲ͜ͷσΟϨΫτϦͰ࡞੒͔ͨ͠Ͱ؅ ཧ͕൥ࡶʹͳΔͷͰɺϥούʔ͕༻ҙ͞ Ε͍ͯΔɻ =>͜ΕΛ࢖ͬͯ؀ڥΛߏங(pipͰΠϯε τʔϧ) 12೥11݄17೔౔༵೔

  10. xshrc(bashrc, zshrc) • virtulenvwrapperΛ࢖ ͏ઃఆ • Ծ૝؀ڥ͸ҰׅͰ؅ཧ • cd(σΟϨΫτϦҠಈ) ͷ࣌ʹউखʹԾ૝؀ڥ

    ͕੾ΓସΘΔΑ͏ʹࡉ ޻[alias cd=‘venv_cd’] 12೥11݄17೔౔༵೔
  11. Ծ૝؀ڥΛ࡞੒͢Δ $ mkvirtualenv <env> [--python=<python path>] 12೥11݄17೔౔༵೔

  12. Ծ૝؀ڥΛ࡟আ͢Δ $ rmvirtualenv <env> 12೥11݄17೔౔༵೔

  13. cdͰԾ૝؀ڥ੾Γସ͑ $ workon <env> # ্ͷ͸ɺcdͨ͠ͱ͖ʹ`.venv`ϑΝΠϧʹॻ͔Εͨ # env໊Λݟͯ੾Γସ͑ͯ·͢ # .zshrc(.bashrc)ʹworkonΛ࣮ߦ͢Δؔ਺Λఆٛ

    12೥11݄17೔౔༵೔
  14. ؀ڥΛҠߦ͢Δ $ pip freeze >requirements.txt $ mkvirtualenv new_env $ pip

    install -r requirements.txt 12೥11݄17೔౔༵೔
  15. ͓ΘΓ 12೥11݄17೔౔༵೔