Macã§Python( virtualenv 㨠virtualenvwrapper ) â
ãã¦æ¨æ¥ã®è»¢è·è©±ã®ç¶ry) ã§ã¯ããã¾ããã
Mac で Python - Study03.net 対シンバシ専用
æ¨æ¥ã®ã¨ã³ããªã§æ¸ãããvirtualenvã¨virtualenvwrapperã®ä½¿ãæ¹ã«ã¤ãã¦ç°¡åã«è¦ãæ¸ãããã¦ãããã¨æãã¾ãã
ã¾ãã¯virtualenvã§ãã
1. 確èª
virtualenvã¨ã¯ãè²ããªãã®ããã·ã§ã£ã¦ç°¡åã«èª¬æããã¨ãPythonã®å®è¡ç°å¢ãä»®æ³åï¼ãã¦ããããã¼ã«ã§ããè¨èããè¯ãããããã®ã§æ¨æ¥ã®ã¤ããä¾ã«ç°¡åã«ãã£ã¦ã¿ã¾ããã
ã¾ãæ¨æ¥ã®ç¶æ ã ã¨ãããã¤ãpipã¢ã¸ã¥ã¼ã«ãã¤ã³ã¹ãã¼ã«ããç¶æ ãªã®ã§ã
pip freeze
ã¨ããä»ã©ããªããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããã¦ãããä¸è¦§ã§ãããã³ãã³ããæã¤ã¨
distribute==0.6.15 mercurial==1.8.2 pep8==0.6.1 pyflakes==0.4.0 virtualenv==1.6 virtualenvwrapper==2.6.3 wsgiref==0.1.2
大ä½ãããªæãã§æå°éã®ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ãããç¶æ ã«ãªã£ã¦ããã¨æãã¾ãããã®ã¾ã¾pip install bucho ã¿ãããªæãã§ãã«ã¹ãããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ãã¦ãã£ã¦ããããã§ãããããããã¨ãsite-package以ä¸ããã«ã¹ãè¥å¤§åãã¦ãã£ã¦è¤æ°ã®éçºããã¸ã§ã¯ãã®ãã®ããåä¸ãã·ã³ã§ãéçºãããã¨ããã¨ããã£ã¡ã®ããã¸ã§ã¯ãã¯ã¢ã¬ãå¿ è¦ã§ãã£ã¡ã¯ã³ã¬ãå¿ è¦ã§ã¨ããæãã§è¨³ãããããªããªãããã§ãã
/usr/local/Cellar/python/2.7.1/lib/python2.7/site-packages
ã¾ããåç´ã«pythonã¨æã¤ã¨ãä»ã¯ /usr/local/bin ã® python(2.7.1) ãå¼ã°ãããããªã£ã¦ãã¾ãããæ°ããéçºããããã®ã¯ãMacã®ããã©ã«ãã«å ¥ã£ã¦ããpython2.6 ã§éçºãããã¨è¡ã£ãå ´åãPATHç°å¢å¤æ°ãããã£ãããã¦ãããããã©ããããã§ãã
2 . ä»®æ³ç°å¢ã®ä½æ
ããéçºããã¸ã§ã¯ããã·ã¹ãã ã ãã®Pythonå®è¡ç°å¢ããå¥ã§ä½ã£ã¦ããã¦ããã®ä¸ã§éçºãããã¨ããæã«åºçªãªã®ããvirtualenvã§ãããã£ãããã£ã¦ã¿ã¾ãããã¾ãvirtualenvãä½ãåã®å®è¡ç°å¢ã確èªãã¦ããã¾ãããã
$ python Python 2.7.1 (r271:86832, Apr 11 2011, 10:32:24) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.9)] on darwin Type "help", "copyright", "credits" or "license" for more information. $ pip freeze distribute==0.6.15 mercurial==1.8.2 pep8==0.6.1 pyflakes==0.4.0 virtualenv==1.6 virtualenvwrapper==2.6.3 wsgiref==0.1.2
確èªãã§ããããä»åã¯ãpython2.6 ã使ããããªä»®æ³ç°å¢ãã~/.testenvãã¨ãã¦ä½ãã¾ãããã
virtualenv --python=/usr/bin/python2.6 ~/.testenv
ã¨ã©ã¼ããªãã»ããã¢ãããå®äºãããããã¼ã ãã£ã¬ã¯ããªã®ä¸ã«ä»®æ³ç°å¢ãä½ããããã¨ã確èªãã¾ãããã
$ ls -la ~/.testenv .Python -> /System/Library/Frameworks/Python.framework/Versions/2.6/Python bin include lib
3. ä»®æ³ç°å¢ã®activate
ä»®æ³ç°å¢ãã§ãããä»åº¦ã¯ä»®æ³ç°å¢ãå®è¡ãã¾ãããã
$ source ~/.testenv/bin/activate
ããããã¨ã·ã§ã«ã®å é ã« (.testenv) ã¨ããã¡ãã»ã¼ã¸ãåºãã®ã確èªã§ããã¨æãã¾ãããã®ç¶æ ããä»®æ³ç°å¢ãå®è¡ããã¦ããç¶æ ã§ãã
(.testenv)hogehoge:.testenv tell_k$
ããã§ãããpython2.6ã使ãæºåãæ´ã£ãã®ã§ãäºåã«ç¢ºèªããã®åãããã«ãpython 㨠pip freezeãã¿ã¦ã¿ã¾ãããã
$ python Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. $pip freeze wsgiref==0.1.2
çµæãå¤ããã¾ããããããã§pythn2.6ã®ä»®æ³çãªå®è¡ç°å¢ãã§ãã¾ããããã¨ã¯ä»®æ³ç°å¢ã§ pip install ã§ããã±ã¼ã¸ã¨ããã¤ã³ã¹ãã¼ã«ããã¨ã.testenv以ä¸ã«ã¤ã³ã¹ã³ããã¦ããã®ã§ãããã©ã®site-packageãæ±ããã«éçºç°å¢ãæ§ç¯ã§ãããã§ãã
ä»®æ³ç°å¢åããæãããã£ãã
$ deactivate
ã¨æã¦ã°æãããã¾ãã
4. ä½è«
è¯ãPythonã®ã¢ããªã¨ããé å¸ãã¦ãã人ãã¡ã¯ãpip freezeã®çµæã requirement.txt ã¿ãããªã®ã«åãåºãã¦ããã¦å¿ è¦ãªããã±ã¼ã¸ãç¾ åãããã®ãä½µãã¦é å¸ãã¦ããã¦ãã¾ãã
$ pip freeze > requirement.txt
ããã±ã¼ã¸ãä¸è¦§ãããããã¹ããå ã«ä¸æ°ã«ã¤ã³ã¹ã³ããã«ã¯
$ pip install -r requirement.txt
ã¨ãã¾ãã
ããããã¢ããªãåããããæã®æé ã¨ãã¦ã¯ã
1. ã¢ããªãDL 2. ä»®æ³ç°å¢ãä½ã (virtualenv ~/.env) 3. ä»®æ³ç°å¢ãactivateãã (source ~/.env/bin/activate) 4. å¿ è¦ãªããã±ã¼ã¸ãã¤ã³ã¹ã³ãã (pip install -r requirement.txt) 5. ã¢ããªãèµ·åãããããããããããããã
ã¿ãããªæé ãè¸ãã®ãè¯ãããã§ãã
ä»æ¥ãæ¯åãæ°å³ãªã®ã§ãããã«virtulenvã楽ã«ä½¿ãããã®virtualenvwrapperã«ã¤ãã¦ã¯å¾æ¥æ¸ãããã¨ãvirtualenvã®ä»çµã¿ã«é¢ãã¦ã¯ä¸è¨ã¨ã³ããªãåèã«ãã¾ãããm( _ _ )m
ã§ã¯ã§ã¯ã¢ãã¥ã¼