{"id":418,"date":"2020-03-20T18:53:54","date_gmt":"2020-03-20T09:53:54","guid":{"rendered":"https:\/\/blog.hgrs.me\/?p=418"},"modified":"2020-03-20T18:53:54","modified_gmt":"2020-03-20T09:53:54","slug":"%e3%80%90macos%e3%80%91python-%e3%81%ae%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89-pyenv-%e3%81%a8-pyenv-virtualenv","status":"publish","type":"post","link":"https:\/\/blog.hgrs.me\/archives\/418.html","title":{"rendered":"\u3010macOS\u3011Python \u306e\u74b0\u5883\u69cb\u7bc9 \u2014 pyenv \u3068 pyenv-virtualenv \u2014"},"content":{"rendered":"

\u306f\u3058\u3081\u306b<\/h2>\n

\u50d5\u306a\u308a\u306e macOS \u3067 Python \u74b0\u5883\u3092\u4f5c\u308b\u305f\u3081\u306e\u304a\u8a71\u3067\u3059\u3002<\/p>\n

pyenv \u3068 pyenv-virtualenv<\/h2>\n

\u3053\u3053\u3067\u306f Python \u306e\u4eee\u60f3\u74b0\u5883\u3092 pyenv<\/a> \u3068 pyenv-virtualenv<\/a> \u3067\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n

pyenv<\/h2>\n

Homebrew \u3092\u7528\u3044\u305f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n

macOS \u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306f Homebrew<\/a> \u3092\u7528\u3044\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002Homebrew \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u30ea\u30f3\u30af\u5148\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n

pyenv \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n

$ brew install pyenv<\/code><\/pre>\n

Git \u3092\u7528\u3044\u305f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n

pyenv \u306e GitHub \u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u30af\u30ed\u30fc\u30f3\u3057\u3066\u304f\u308b\u3053\u3068\u3067\u3082\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n

$ git clone https:\/\/github.com\/pyenv\/pyenv.git ~\/.pyenv<\/code><\/pre>\n

\u30d1\u30b9\u306e\u8ffd\u52a0\u3068\u521d\u671f\u5316<\/h3>\n

\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f pyenv \u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u30d1\u30b9\u3092\u901a\u3057\u3001\u30b7\u30a7\u30eb\u5b9f\u884c\u6642\u306b\u521d\u671f\u5316\u3092\u3057\u3066\u3084\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

\u4eca\u56de\u306f\u6700\u65b0\u306e macOS \u6a19\u6e96\u306e Z Shell( zsh ) \u306e\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002
\nBash \u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u65b9\u306f\u9069\u5b9c .zshrc<\/code> \u3092 .bash_profile<\/code> \u306a\u3069\u306b\u8aad\u307f\u66ff\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

\u5b9f\u884c\u3059\u308b\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n

$ echo 'export PYENV_ROOT="$HOME\/.pyenv"' >> ~\/.zshrc\n$ echo 'export PATH="$PYENV_ROOT\/bin:$PATH"' >> ~\/.zshrc\n$ echo -e 'if command -v pyenv 1>\/dev\/null 2>&1; then\\n  eval "$(pyenv init -)"\\nfi' >> ~\/.zshrc<\/code><\/pre>\n

Python \u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u8ffd\u52a0<\/h3>\n

\u4eee\u60f3\u74b0\u5883\u306e\u305f\u3081\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u8ffd\u52a0\u3059\u308b\u306b\u306f\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002<\/p>\n

$ pyenv install x.x.x<\/code><\/pre>\n

\u3053\u306e\u969b\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u53ef\u80fd\u306a\u30d0\u30fc\u30b8\u30e7\u30f3\u4e00\u89a7\u306f pyenv install -l<\/code> \u3067\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u307e\u305f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30d3\u30eb\u30c9\u3059\u308b\u5834\u5408\u306a\u3069\u306f\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u3057\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n

$ env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install x.x.x<\/code><\/pre>\n

pyenv-virtualenv<\/h2>\n

Homebrew \u3092\u7528\u3044\u305f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n

pyenv \u3068\u540c\u3058\u304f Homebrew \u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3059\u3002\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n

$ brew install pyenv-virtualenv<\/code><\/pre>\n

Git \u3092\u7528\u3044\u305f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n

\u3053\u3061\u3089\u3082 pyenv \u3068\u540c\u3058\u304f Git \u3067\u3082\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3059\u3002\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n

$ git clone https:\/\/github.com\/pyenv\/pyenv-virtualenv.git $(pyenv root)\/plugins\/pyenv-virtualenv<\/code><\/pre>\n

\u521d\u671f\u5316<\/h3>\n

pyenv \u540c\u69d8\u306b\u3001\u521d\u671f\u5316\u306e\u30b3\u30de\u30f3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n

$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~\/.zshrc<\/code><\/pre>\n

\u4eee\u60f3\u74b0\u5883\u306e\u8ffd\u52a0<\/h3>\n

\u4eee\u60f3\u74b0\u5883\u3092\u8ffd\u52a0\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n

$ pyenv virtualenv x.x.x <name><\/code><\/pre>\n

\u4f8b\u3048\u3070\u3001Python 3.8.2 \u3067 test-3.8 \u3068\u3044\u3046\u540d\u524d\u306e\u74b0\u5883\u3092\u4f5c\u308a\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

$ pyenv virtualenv 3.8.2 test-3.8<\/code><\/pre>\n

\u4eee\u60f3\u74b0\u5883\u306e\u6307\u5b9a<\/h2>\n

\u30b0\u30ed\u30fc\u30d0\u30eb<\/h3>\n

\u7279\u5225\u306b\u3001\u74b0\u5883\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u306a\u74b0\u5883\u3067\u4f7f\u3046\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a\u3059\u308b\u306b\u306f pyenv global<\/code> \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f test-3.8<\/code> \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

$ pyenv global test-3.8<\/code><\/pre>\n

\u30ed\u30fc\u30ab\u30eb<\/h3>\n

\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3001\u7279\u5b9a\u306e\u4eee\u60f3\u74b0\u5883\u3092\u6307\u5b9a\u3059\u308b\u5834\u5408\u306b\u306f pyenv local<\/code> \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f test-3.8<\/code> \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

$ pyenv local test-3.8<\/code><\/pre>\n

\u3053\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b .python-version<\/code> \u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u8ffd\u52a0\u3055\u308c\u3001\u305d\u3053\u306b\u3001\u6307\u5b9a\u3057\u305f\u4eee\u60f3\u74b0\u5883\u304c\u66f8\u304d\u8fbc\u307e\u308c\u307e\u3059\u3002<\/p>\n

\u307e\u305f\u3001pyenv activate <name><\/code> \u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u4eee\u60f3\u74b0\u5883\u3092\u4e00\u6642\u7684\u306b\u8d77\u52d5\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u4eee\u60f3\u74b0\u5883\u306e\u78ba\u8a8d<\/h2>\n

\u73fe\u5728\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u4eee\u60f3\u74b0\u5883\u306e\u4e00\u89a7\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f pyenv versions<\/code> \u304c\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u4e00\u89a7\u3067\u306f\u306a\u304f\u3001\u73fe\u5728\u306e\u74b0\u5883\u3067\u9069\u7528\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3092\u77e5\u308a\u305f\u3044\u5834\u5408\u306b\u306f pyenv version<\/code> \u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u304a\u308f\u308a\u306b<\/h2>\n

\u3053\u3053\u3067\u7d39\u4ecb\u3057\u305f\u4ed6\u306b\u5fc5\u8981\u305d\u3046\u306a\u30b3\u30de\u30f3\u30c9\u304c\u51fa\u3066\u304d\u305f\u3089\u3001\u8ffd\u8a18\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u306f\u3058\u3081\u306b \u50d5\u306a\u308a\u306e macOS \u3067 Python \u74b0\u5883\u3092\u4f5c\u308b\u305f\u3081\u306e\u304a\u8a71\u3067\u3059\u3002 pyenv \u3068 pye…<\/p>\n","protected":false},"author":1,"featured_media":419,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[14],"_links":{"self":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts\/418"}],"collection":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/comments?post=418"}],"version-history":[{"count":0,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts\/418\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/media\/419"}],"wp:attachment":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/media?parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/categories?post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/tags?post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}