Save 37% off PRO during our Black Friday Sale! »

Python 環境構築方法 2016

246d2365fbcf6685ff7eaa084d1361ea?s=47 2bo
October 16, 2016

Python 環境構築方法 2016

機械学習名古屋 第7回勉強会 発表資料

246d2365fbcf6685ff7eaa084d1361ea?s=128

2bo

October 16, 2016
Tweet

Transcript

  1. Keynote LiveͰ ͜ͷεϥΠυΛ഑৴ͯ͠·͢ɻ

  2. ͓લ୭Α • ໊લɿ
 ௶಺ ༝޹ (@2box2bo) • blogɿ
 http://www.zumwalt.info/blog •

    ॴଐ
 EjectίϚϯυϢʔβʔձ
 http://eject.kokuda.org/
 Python౦ւ (ڞಉ؅ཧਓ)
 http://connpass.com/series/292/
  3. ػցֶश໊ݹ԰ɺॳࢀՃͰ͢ɻ

  4. ͪͳΈʹ

  5. ػցֶश͸શ͘஌Γ·ͤΜʂ

  6. ͳͷͰ…

  7. Python؀ڥߏஙํ๏ͷ࿩Λ͠·͢

  8. ͦͯ͠ɺPython౦ւษڧձʹ དྷΔͷͰ͢…

  9. ஌ͬͯΔɺ Python࢖Θͳ͍ͬͯํ͸ ૉ਺Ͱ΋਺͍͑ͯͯͩ͘͞

  10. Python؀ڥߏஙํ๏ 2016 ػցֶश ໊ݹ԰ ୈ7ճษڧձ 2016/10/15 @2box2bo

  11. ஫ҙࣄ߲ • ͜ͷߏஙखॱ͸།ҰແೋͷखॱͰ͸͋Γ·ͤΜɻ
 
 ҟ࿦͸ೝΊΔʂ • ͳΔ΂ࣦ͘ഊ͠ͳ͍खॱΛॻ͍ͯ·͕͢ɺࣦഊ͠ ͯ΋ٽ͔ͳ͍ɻ • ࣮ࢪ͸ࣗݾ੹೚Ͱɻ

  12. Pythonͬͯʁ • ػցֶशʮ͔͠ʯͰ͖ͳ͍ݴޠͰ͸͋Γ·ͤΜɻ • ػցֶशʮ΋ʯͰ͖ΔݴޠͰ͢ɻ • ػցֶशؔ࿈ͷϥΠϒϥϦ͸๛෋Ͱ͕͢ɺػցֶ शҎ֎Ͱ΋࢖ΘΕ͍ͯ·͢ɻ
 ͨͱ͑͹ʮ͋ͱ΋͏1λʔϯ͚ͩ…ʯͰ༗໊ͳ Civilization4͸StaklessPythonͰॻ͔Εͯ·͢ɻ

  13. ϞϯςεϚʂ

  14. Agenda • PythonԾ૝؀ڥ • Linux(CentOS) ΁ͷΠϯετʔϧखॱ • macOS ΁ͷΠϯετʔϧखॱ •

    pyenv-virtualenvͷ࢖͍ํ • Windows10 ΁ͷΠϯετʔϧखॱ • Anacondaͷ࢖͍ํ
  15. PythonԾ૝؀ڥ

  16. ໰. ҎԼͷҧ͍Λઆ໌͠ͳ͍͞ • pyenv • virtualenv • pyenv-virtualenv

  17. ͜ͷ΍΍͕͜͠͞ॳ৺ऀΛ໎ΘͤΔ

  18. pyenv • ৭ʑͳPythonόʔδϣϯΛ؅ཧ͢Δπʔϧ • Python2ܥͱ3ܥΛ੾Γସ͑ͯ࢖͑Δ • shell΍σΟϨΫτϦͰ࢖༻͢ΔPythonΛࢦఆՄೳ • ಉҰόʔδϣϯͷPythonͰϥΠϒϥϦΛ੾Γସ͑ ͯ࢖͏͜ͱ͸Ͱ͖ͳ͍

    • WindowsͰ͸࢖͑ͳ͍
  19. pyenv ͷΠϝʔδ Python 2.7 Python 2.6 Python 3.5 QZFOW CT

    OVNQZ CT OVNQZ
  20. virtualenv • ಉҰόʔδϣϯͷPythonͰ࢖༻͢ΔϥΠϒϥϦΛ ੾Γସ͑ͯ࢖͑ΔΑ͏ʹ͢Δπʔϧ • Python2ܥͱ3.2·Ͱͷ3ܥͰ࢖༻
 Python3.3Ҏ߱͸pyvenvͱ͍͏πʔϧʹͳͬͨʁ • pyenv ͱ͸ແؔ܎

    • pip ͰΠϯετʔϧͰ͖Δ • WindowsͰ΋࢖͑Δ
  21. virtualenv ͷΠϝʔδ bs4-test numpy-test develop WJSUVBMFOW CT OVNQZ CT OVNQZ

    Python 3.1
  22. pyenv-virtualenv • pyenvͰಉҰόʔδϣϯͷPythonͰϥΠϒϥϦΛ ੾Γସ͑ͯ࢖͑ΔΑ͏ʹͨ͠πʔϧ • virtualenv ͱ͸ແؔ܎ • ࡞ऀ͸pyenvͱಉ͡ํ •

    ΋ͪΖΜWindowsͰ͸࢖͑ͳ͍
  23. pyenv-virtualenv ͷΠϝʔδ Python 2.7 Python 2.7 Python 3.5 QZFOWWJSUVBMFOW CT

    OVNQZ CT OVNQZ bs4-test numpy-test develop
  24. ؆୯ͳ·ͱΊ • pyenv • ෳ਺όʔδϣϯͷPythonΛ੾Γସ͑ͯ࢖͑Δɻ • WindowsͰ͸࢖͑ͳ͍ɻ • virtualenv •

    PythonͷϥΠϒϥϦ؀ڥΛ੾Γସ͑ͯ࢖͑Δɻ • WindowsͰ࢖͑Δɻ • pyenv-virtualenv • pyenvʹvirtualenvͷػೳΛ௥Ճ͢Δɻ • WindowsͰ͸࢖͑ͳ͍ɻ
  25. ௐ΂Δ࣌͸هࡌ͞Ε͍ͯΔͷ͕ virtualenvͳͷ͔ɺ pyenv-virtualenvͳͷ͔Λ ؾʹ͢Δɻ

  26. ࠓճߏங͢ΔPython؀ڥ • Linux (CentOS7)
 pyenv + pyenv-virtualenv
 • macOS Sierra


    pyenv + pyenv-virtualenv
 • Windows10
 Anaconda
  27. OSඪ४ͰΠϯετʔϧ͞Ε͍ͯΔ
 PythonΛมߋ͢Δͱؒҧ͍ͳ͘ τϥϒϧʹͳΓ·͢ɻ ※ ܦݧஊ

  28. Linux(CentOS) ΁ͷ Πϯετʔϧखॱ

  29. ߏங؀ڥ • CentOS Linux release 7.2.1511 (Core) • selinux ͸enforcing

    Ҏ֎Ͱ… • root࢖༻
  30. pyenv Πϯετʔϧ • ඞཁύοέʔδͷΠϯετʔϧ # yum install -y gcc gcc-c++

    make git patch openssl-devel zlib-devel readline-devel sqlite- devel bzip2-devel • μ΢ϯϩʔυ # git clone https://github.com/yyuu/pyenv.git / usr/local/pyenv/
  31. pyenv Πϯετʔϧ • ؀ڥม਺ઃఆ # export PYENV_ROOT="/usr/local/pyenv" # export PATH=“/usr/local/pyenv/bin:$PATH"

    • python Πϯετʔϧ # pyenv install 3.5.2
  32. pyenv-virtualenv Πϯετʔϧ • pyenv-virtualenv Πϯετʔϧ # cd /usr/local/pyenv/plugins/ # git

    clone https://github.com/yyuu/pyenv-virtualenv.git # git clone https://github.com/yyuu/pyenv-virtualenvwrapper.git
  33. pyenv-virtualenv Πϯετʔϧ • ؀ڥม਺ઃఆ # cat <<EOF >> ~/.bashrc if

    [ -f /usr/local/pyenv/bin/pyenv ]; then export PYENV_ROOT="/usr/local/pyenv" export PATH="/usr/local/pyenv/bin:\$PATH" eval "\$(pyenv init -)" PS1='(pyenv:\`pyenv version-name\`)'\$PS1 fi EOF
  34. macOS ΁ͷ Πϯετʔϧखॱ

  35. ߏங؀ڥ • macOS Sierra 10.12 • HomeBrewΛ࢖༻

  36. HomeBrew Πϯετʔϧ • ඞཁύοέʔδͷΠϯετʔϧ $ ruby -e "$ curl -fsSL

    https:// raw.githubusercontent.com/Homebrew/install/ master/install ” • ҎԼ͕දࣔ͞ΕͨΒEnter Press RETURN to continue or any other key to abort
  37. pyenv-virtualenv Πϯετʔϧ • pyenv-virtualenv Πϯετʔϧ $ brew install pyenv-virtualenv •

    ؀ڥม਺ઃఆ $ echo 'export PYENV_ROOT="/usr/local/var/pyenv"' >> ~/.bash_profile $ echo 'if which pyenv > /dev/null then eval "$ pyenv init - " fi' >> ~/.bash_profile $ echo 'if which pyenv-virtualenv-init > /dev/null then eval "$ pyenv virtualenv-init - " fi' >> ~/.bash_profile $ source .bash_profile
  38. Python Πϯετʔϧ • Python Πϯετʔϧ $ pyenv install 3.5.2

  39. pyenv-virtualenvͷ࢖͍ํ

  40. pyenv-virtualenvͷ࢖͍ํ • Linuxɺmacڞ௨Ͱ͢ɻ • ΠϯετʔϧՄೳͳPythonͷҰཡදࣔ # pyenv install -l •

    python Πϯετʔϧ # pyenv install [Ұཡʹ͋Δόʔδϣϯ໊]
  41. pyenv-virtualenvͷ࢖͍ํ • python Ծ૝؀ڥ࡞੒ # pyenv virtualenv [Pythonόʔδϣϯ] [Ծ૝؀ڥ໊] ྫ)

    # pyenv virtualenv 2.7.11 Py2Base
 # pyenv virtualenv Py2Base py2-test Ծ૝؀ڥ͔Β৽͍͠Ծ૝؀ڥΛ࡞ͬͨ৔߹͸ϥ ΠϒϥϦ౳΋Ҿ͖ܧ͕Ε·͢
  42. pyenv-virtualenvͷ࢖͍ํ • python Ծ૝؀ڥ࡟আ # pyenv uninstall [Ծ૝؀ڥ໊] ֬ೝ͕Ͱͯ͘ΔͷͰyesΛೖྗ

  43. pyenv-virtualenvͷ࢖͍ํ • ඪ४Ͱ࢖༻͢ΔPythonΛมߋ # pyenv global [Ծ૝؀ڥ໊] • ݱࡏͷshellͷPythonΛมߋ #

    pyenv shell [Ծ૝؀ڥ໊] • ݱࡏͷσΟϨΫτϦͷPythonΛมߋ # pyenv local [Ծ૝؀ڥ໊]
  44. pyenv-virtualenvͷ࢖͍ํ • Ծ૝؀ڥͷҰཡදࣔ # pyenv versions • PyEnvͷΞοϓσʔτ # cd

    /usr/local/pyenv # git pull 
 ৽͍͠VersionͷPythonΛΠϯετʔϧ͢Δ࣌ʹ ΞοϓσʔτΛ࣮ࢪ͢Δ
  45. Windows10 ΁ͷ Πϯετʔϧखॱ

  46. ߏங؀ڥ • Windows10 Version 1607 • pyenv͸ΠϯετʔϧͰ͖ͳ͍ͷͰAnaconda Λ࢖༻

  47. Anacondaͱ͸ • PythonΛ͓खܰʹΠϯετʔϧͰ͖Δπʔϧ • ෳ਺όʔδϣϯͷPython؅ཧ΍ಉҰόʔδϣϯ PythonͷϥΠϒϥϦ؅ཧ͕Մೳ • ηοτͰIPython΍Jupyter NotebookɺSpyder౳ ͷπʔϧ΍ϥΠϒϥϦ͕Πϯετʔϧ͞ΕΔɻ

    • miniconda Λ࢖͏ͱ࠷௿ݶͷPython؀ڥ͕Πϯε τʔϧ͞ΕΔɻ • WindowsҎ֎ʹ΋LinuxɺmacʹରԠ • LinuxɺmacͰ͸pyenvͱ૊Έ߹Θͤ΋Մೳ
  48. Anaconda μ΢ϯϩʔυ • Anaconda
 https://www.continuum.io/downloads • miniconda
 http://conda.pydata.org/miniconda.html • 3ܥΛબΜͰ΋ޙ͔Β2ܥͷΠϯετʔϧՄೳ


    ٯʹ2ܥΛબΜͰ΋3ܥΛΠϯετʔϧՄೳ
  49. • GUIͰϙνϙνʔͬͱͳɻ Anaconda Πϯετʔϧ

  50. Anacondaͷ࢖͍ํ

  51. Anacondaͷ࢖͍ํ • ΠϯετʔϧՄೳͳPythonͷදࣔ > conda search • Ծ૝؀ڥߏங > conda

    create -n [໊લ] python=[Versionࢦఆ] • Ծ૝؀ڥҰཡදࣔ > conda env list
  52. Anacondaͷ࢖͍ํ • Ծ૝؀ڥ࡟আ > conda remove -n [໊લ] —all •

    Ծ૝؀ڥ੾Γସ͑ > activate [໊લ] • Ծ૝؀ڥΛൈ͚Δ > deavtivate
  53. Ͷɺ؆୯Ͱ͠ΐʁ

  54. None
  55. ͔͜͜Βએ఻(ຊ൪)

  56. Python౦ւͷ঺հ

  57. Python౦ւ͸ ϓϩάϥϛϯάݴޠ ʮPythonʯ ͷ౦ւ஍ํ ίϛϡχςΟͰ͢

  58. Python౦ւ • Pythonͷ౦ւ஍ํ஍ҬϩʔΧϧίϛϡχςΟ • ΏΔ;ΘͩΑʂ • PythonͬΆ͚Ε͹Կൃදͯ͠΋େৎ෉ͩΑʂ • ා͘ͳ͍Αʂ •

    PyͬͯͲ͔ͬʹ෇͍ͯΕ͹͍͍ͩͨOKʂʂ
  59. PythonωλൃදͰ͖·͢ʂ

  60. ػցֶशωλ΋OKʂ

  61. RaspberryPiωλ΋OKʂ

  62. ύΠ͕͍ͭͯΕ͹OK

  63. ͦΜͳΏΔ;ΘͰૉఢͳ Python౦ւͷษڧձ͕…

  64. 10݄29೔(౔) ʹ։࠵ʂ ʮୈ31ճ Python౦ւ ษڧձʯ

  65. ਃࠐɾৄࡉ͸connpassͰʂ
 http://connpass.com/event/40191/

  66. ੋඇɺ͓͍ͩ͘͜͠͞ɻ

  67. ͓ΘΓ