Macã«pythonbrew+virtualenvã§Pythonç°å¢ãä½ã£ã¦ã¿ã
RubyãPerlã¨ããã®ã§æ®ãPythonã«ã¤ãã¦ãpythonbrewã¨virtualenvã§ç°å¢ãæ´ãã¦ã¿ããããå æ¸å
容ããã³ãã¬çã§é£½ãã¦ãããã©ï½
PythonãSnow Leopardã§ã¯2.6.1ãªã®ã§2.7ã¨ã3.2ã使ãããããã¼ã£ã¦ãã¨ã§ã
ã¿ã¤ãã«ã«ã¯ãMacã§ããã£ã¦å
¥ã£ã¦ããã©ãpythonbrewèªä½ã¯UNIXç³»ã®ç°å¢ã§ä½¿ãã¾ãã
pythonbrewã£ã¦ããã®ã¯ãè¤æ°ã®Pythonãã¼ã¸ã§ã³ãç°¡åã«ã¤ã³ã¹ãã¼ã«ãããåãæ¿ãããã§ããããã«ãããã¼ã«ã§ãRubyã§ããã°RVMãPerlã§ããã°perlbrewã¿ãããªããã*1
ããã使ãã°OSæ¨æºã®ç°å¢ãæ±ããªããã2.6ç³»ã2.7ç³»ã3ç³»ã¨ãããã¸ã§ã¯ãã§ä½¿ç¨ä¸ã®ãã¼ã¸ã§ã³ã¨ææ°çã¨ãè²ã
ãªè¤æ°ã®ç°å¢ãç°¡åã«å
±åããã¦ä½¿ãåãããã¨ãã§ãããã¹ããï¼
pythonbrewã使ãã¨ãããªæãã§ãµã¯ãµã¯ç°å¢ã使ãåãããã¨ãã§ããããã«ãªãã
pythonbrew install 2.7.2 âPython-2.7.2ãã¤ã³ã¹ãã¼ã« pythonbrew install 3.2 âPython-3.2ãã¤ã³ã¹ãã¼ã« pythonbrew switch 2.7.2 âPython-2.7.2ã«åãæ¿ã pythonbrew switch 3.2 âPython-3.2ã«åãæ¿ã
virtualenvã£ã¦ããã®ã¯ãPythonã®æ°ããç¬ç«ããç°å¢ãæ§ç¯ãã¦èªç±ã«åãæ¿ãã¦ä½¿ããããã«ãããã¼ã«ã
pythonbrewã¨ä½ãéãã®ãã¨ããã¨ãpythonbrewã¯Pythonã®ã¤ã³ã¹ãã¼ã«ãã管çãã¦ãããã®ã«å¯¾ãã¦ãvirtualenvã¯æ¢åã®å®è¡ç°å¢ãå
ã«ãã¦æ°ããä»®æ³ç°å¢ãä½ã£ã¦ãããç¹ãç°ãªãã
virtualenvã¨ããã¨ããã便å©ã«ããvirtualenvwrapperã£ã¦ããã®ã使ãã¨ãããªæãã§ãµã¯ãµã¯ç°å¢ã使ãåãããã¨ãã§ããããã«ãªãã
mkvirtualenv -p /path/to/python-2.6 foo â2.6ããã¼ã¹ã«fooã¨ããç°å¢ãä½æ mkvirtualenv -p /path/to/python-2.6 foo2 â2.6ããã¼ã¹ã«foo2ã¨ããç°å¢ãä½æ mkvirtualenv -p /path/to/python-3.2 bar â3.2ããã¼ã¹ã«barã¨ããç°å¢ãä½æ workon foo âfooç°å¢ã«åãæ¿ã workon bar âbarç°å¢ã«åãæ¿ã deactivate âvirtualenvã®ç°å¢ããæãã¦OSæ¨æºã«æ»ã
ã©ã£ã¡ãã§ããããããªããã£ã¦æ°ããããã©ãããæãããªãããã§ãããã ã¨æãã
ã¨ããããpythonbrewã§æ°ããã¤ã³ã¿ããªã¿ãã¤ã³ã¹ãã¼ã«ãã¦ãvirtualenvã§ç¨éå¥ã«ã½ãã½ãç°å¢ãå¢ããã¦ããã¨ããã®ãæµè¡ããããï¼ï¼ï¼ã®ã§ããã«å£ã£ã¦ã¿ãã
pythonbrewã®ã¤ã³ã¹ãã¼ã«
pythonbrewã®ã¤ã³ã¹ãã¼ã«æ¹æ³ã¯å ¬å¼ãµã¤ãã«æ¸ãã¦ããã³ãã³ããå©ãã°ç°¡åã«å ¥ãã
GitHub - utahta/pythonbrew: Python Environment manager
curl -kLO https://github.com/utahta/pythonbrew/raw/master/pythonbrew-install chmod +x pythonbrew-install ./pythonbrew-install
æµãã¨ãã¦ã¯ãããªæãã
- ã¤ã³ã¹ãã¼ã«ã¹ã¯ãªãããè½ã¨ãã¦ã·ã§ã«ã§å®è¡
- $HOME/.pythonbrew/etc/bashrcã.bash_profileã¨ã.bashrcã§èªã¿è¾¼ãããã«ãã
perlbrewã¨åãã ãã
ããã§$HOME/.pythonbrewã«pythonbrewã®ç°å¢ãã§ããããã
pythonbrewã«é¢ããã³ãã³ã
pythonbrewã§å ¥ãããã¨ã®ã§ãããã¼ã¸ã§ã³ä¸è¦§
pythonbrew list -k
pythonbrewã®ã¢ãããã¼ã
pythonbrew update
ããã§pythonbrewãææ°ã«ãªãã
Pythonã®ã¤ã³ã¹ãã¼ã«
Pythonã®ã¤ã³ã¹ãã¼ã«
pythonbrew install 2.7.2
ããã§Python-2.7.2ãã¤ã³ã¹ãã¼ã«ãããã
å¥åãã¤ãã¦ã¤ã³ã¹ãã¼ã«
pythonbrew install --as=mypython 2.7.2
ããã§Python-2.7.2ãmypythonã¨ããååã§ã¤ã³ã¹ãã¼ã«ãããã
configureãªãã·ã§ã³ãæå®ãã
pythonbrew install --configure="CC=gcc_4.1" 2.7.2
ã¢ã³ã¤ã³ã¹ãã¼ã«
pythonbrew uninstall 2.7.2
Pythonbrewãåãæ¿ãã
å ¥ã£ã¦ãPythonä¸è¦§
pythonbrew list
ããã§ã¤ã³ã¹ãã¼ã«ããã¦ããPythonã®ä¸è¦§ã表示ãããã
Pythonãåãæ¿ãã
pythonbrew switch 2.7.2
ããã§2.7.2ã使ãããã®PATHã¨ããã®ä»ã®ç°å¢å¤æ°ãåãæ¿ãã£ãã®ã§ãä»ããPython-2.7.2ã使ããç¶æ
ã«ãªãã
RVMã¨ã¯éãperlbrewã¨åãã§æ°¸ç¶çã«åãæ¿ãã£ãç¶æ
ã«ãªãã
ç¾å¨ã®ã·ã§ã«ã ãåãæ¿ãã
pythonbrew use 2.7.2
åãæ¿ãç¶æ ã¯ãã®ã·ã§ã«ã ãã
OSæ¨æºã®Pythonã«æ»ã
pythonbrew off
ããã§perlbrewã§å
¥ãããã¤ãããªãç°å¢ã«æ»ãã
è¤æ°ã®Pythonã§ã¾ã¨ãã¦å®è¡
pythonbrewã«ã¯ã¤ã³ã¹ãã¼ã«ãã¦ããPythonã§ã¾ã¨ãã¦å®è¡ããæ©è½ãããã
ãããå©ç¨ããã¨æ¸ããããã°ã©ã ãä»ã®ãã¼ã¸ã§ã³ã§ãã¡ããã¨åããä¸çºã§ãã¹ãã§ããã
ã¾ã¨ãã¦å®è¡
pythonbrew py hello.py
pythonbrewã§ã¤ã³ã¹ãã¼ã«ããå ¨Pythonã§å®è¡ãããã
ç¹å®ã®ãã¼ã¸ã§ã³ã§å®è¡
pythonbrew py -p 2.6.6 -p 2.7.2 hello.py
2.6.6ã¨2.7.2ã§å®è¡ãããã
ãªã³ã¯ãå¼µã
pythonbrew symlink
ããããã¨py2.6ã¨ãpy2.7.2ã¿ãããªãªã³ã¯ã.pythonbrew/binã«åºæ¥ãã®ã§æ軽ã«å®è¡åºæ¥ãããã«ãªãã
ãã ãpythonbrew offããã¨ãªã³ã¯ãæ¶ãã¦ãã¾ãã¿ããã
ãã¨ãå®ã¯pythonbrewã¯pybrewã¨ããã³ãã³ãåã§ãå®è¡ã§ããã
virtualenvã¨virtualenvwrapper
ç¶ãã¦virtualenvã®ã¤ã³ã¹ãã¼ã«ã
ã¨ããããã©ãã§ãããã®ã§virtualenvãå
¥ãããç°å¢ã«switchããã
pythonbrew switch 2.7.2
pipã§virtualenvã¨virtualenvwrapperãã¤ã³ã¹ãã¼ã«ã
pythonbrewã«ãã£ã¦easy_installã¨pipãã¤ã³ã¹ãã¼ã«ããã¦ããã
pip virtualenv virtualenvwrapper
.bashrcã¨ãã«ç°å¢å¤æ°VIRTUALENVWRAPPER_PYTHONãè¨å®ããã
VIRTUALENVWRAPPER_PYTHON=$HOME/.pythonbrew/pythons/Python-2.7.2/bin/python
pythonbrew symlinkã§ã§ããpy2.7.2ã¨ããæå®ããã®ãããã£ã½ããã ãã©ãpythonbrew offããã¨æ¶ãã¡ããã®ã§ç´ã«æå®ãã¦ã¿ãã
.bashrcã¨ãã§virtualenvwrapper.shãèªã¿è¾¼ãã
source $HOME/.pythonbrew/pythons/Python-2.7.2/bin/virtualenvwrapper.sh
ãããpythonbrew symlink -d 2.7.2 virtualenvwrapper.shã¨ãã§ã§ããã®ãæå®ããã£ã½ããã ãã©ï¼ï½ï½
virtualenvã§ç°å¢ãæä½ãã
ã¾ã¼ãåé ã®ãµã³ãã«ã®éãã
ãã以å¤ã«ä¸è¦§ã表示ããlsvirtualenvã¨ããç°å¢ãåé¤ããrmvirtualenvã¨ãè²ã
ããã
詳ããã¯公式ドキュメントã®ã³ãã³ããªãã¡ã¬ã³ã¹ãåç
§ã
åè
*1:perlbrewã«ã¤ã³ã¹ãã¤ã¢ããã¦ã§ãããããã