Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Starting Python

Starting Python

Pythonを始められるような基本的なところ

Kentaro Kawano

July 10, 2017
Tweet

More Decks by Kentaro Kawano

Other Decks in Programming

Transcript

  1. CentOSͳΒPython͕ΠϯετʔϧࡁΈ $ python Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)

    [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print "Hello World" Hello World >>> exit()
  2. SDKͷόʔδϣϯ؅ཧ ෳ਺ͷPythonΛΠϯετʔϧ͢Δͱ… % ls /usr/local/bin/python3* /usr/local/bin/python3@ /usr/local/bin/python3.5m-config@ /usr/local/bin/python3-32@ /usr/local/bin/python3.6@ /usr/local/bin/python3-config@

    /usr/local/bin/python3.6-32@ /usr/local/bin/python3.5@ /usr/local/bin/python3.6-config@ /usr/local/bin/python3.5-32@ /usr/local/bin/python3.6m@ /usr/local/bin/python3.5-config@ /usr/local/bin/python3.6m-config@ /usr/local/bin/python3.5m@ ͜͏ͳΔɻ
  3. ݸผͷϓϩδΣΫτͷόʔδϣϯ͸ʁ • venv Λ࢖ͬͯSDKࣗମΛόϯυϧ͢Δ % pwd /Users/kekawano/hoge % python3.5 -m

    venv venv % ls venv/ % ls venv/ bin/ include/ lib/ pip-selfcheck.json pyvenv.cfg
  4. venv ͷ࢖͍ํ • όʔδϣϯͷݻఆ • ࢖͍͍ͨpython -m venv σΟϨΫτϦ໊ •

    ༗ޮԽ • source σΟϨΫτϦ໊/bin/activate • ແޮԽ • deactivate
  5. ྫ % which python /usr/bin/python % source venv/bin/activate % which

    python /Users/kekawano/hoge/venv/bin/python % python -V Python 3.5.1 % deactivate % python -V Python 2.7.10
  6. ύοέʔδ؅ཧ • pip Λ࢖͏ % which pip /Users/kekawano/hoge/venv/bin/pip % pip

    install flask % pip show flask ... Location: /Users/kekawano/hoge/venv/lib/python3.5/site-packages ... • venv Ͱ؀ڥ͕ด͍ͯ͡ΔͷͰGlobalʹӨڹ͠ͳ͍ • PyPI - the Python Package Index : Python Package Index
  7. ؆୯ͳWebΞϓϦ from flask import Flask app = Flask(__name__) @app.route("/") def

    hello(): return "Hello world!" if __name__ == "__main__": app.run()