{"id":4638,"date":"2024-02-22T13:40:57","date_gmt":"2024-02-22T04:40:57","guid":{"rendered":"https:\/\/blog.since2020.jp\/?p=4638"},"modified":"2024-02-22T13:40:57","modified_gmt":"2024-02-22T04:40:57","slug":"%e3%80%90%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%e3%80%91python%e4%bb%ae%e6%83%b3%e7%92%b0%e5%a2%83venv%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6%e3%81%ae%e8%a9%b1","status":"publish","type":"post","link":"https:\/\/since2020.jp\/media\/%e3%80%90%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%e3%80%91python%e4%bb%ae%e6%83%b3%e7%92%b0%e5%a2%83venv%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6%e3%81%ae%e8%a9%b1\/","title":{"rendered":"\u3010\u74b0\u5883\u69cb\u7bc9\u3011Python\u4eee\u60f3\u74b0\u5883venv\u306b\u3064\u3044\u3066\u306e\u8a71"},"content":{"rendered":"\n<p>Python\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u304a\u3044\u3066\u3001\u7570\u306a\u308b\u4f9d\u5b58\u95a2\u4fc2\u9593\u3067\u306e\u885d\u7a81\u3092\u907f\u3051\u3001\u958b\u767a\u74b0\u5883\u3092\u4e00\u8cab\u3055\u305b\u308b\u3053\u3068\u306f\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u6210\u529f\u306b\u4e0d\u53ef\u6b20\u3067\u3059\u3002Python\u306evenv\u306f\u3001\u3053\u306e\u3088\u3046\u306a\u554f\u984c\u306b\u5bfe\u51e6\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3042\u308a\u3001\u958b\u767a\u8005\u304c\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3054\u3068\u306b\u72ec\u7acb\u3057\u305f\u4eee\u60f3\u74b0\u5883\u3092\u3053\u306e\u30d6\u30ed\u30b0\u3067\u306f\u3001venv\u306e\u4f7f\u3044\u65b9\u3092mkdir\u304b\u3089\u3001\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u307e\u3067\u3092\u89e3\u8aac\u3057\u307e\u3059\uff01<\/p>\n\n\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p><strong><span style=\"font-size: 18pt;\">venv\u3068\u306f\u2026<\/span><\/strong><\/p>\r\n<blockquote>\r\n<p><span style=\"font-size: 12pt;\">&#8221;<code>venv<\/code>\u00a0\u30e2\u30b8\u30e5\u30fc\u30eb\u306f\u3001\u8efd\u91cf\u306a\u4eee\u60f3\u74b0\u5883\u306e\u4f5c\u6210\u3092\u884c\u3044\u307e\u3059\u3002\u305d\u308c\u305e\u308c\u306e\u4eee\u60f3\u74b0\u5883\u306f\u3001<code>site<\/code>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u72ec\u7acb\u3057\u305f Python \u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u96c6\u5408\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002\u4eee\u60f3\u74b0\u5883\u306f\u3001\u30d9\u30fc\u30b9 Python \u3068\u3082\u547c\u3070\u308c\u308b\u3001\u3059\u3067\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b Python \u306e\u4e0a\u306b\u4f5c\u6210\u3055\u308c\u3001\u660e\u793a\u7684\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u307f\u304c\u5229\u7528\u53ef\u80fd\u3068\u306a\u308b\u3088\u3046\u3001\u30d9\u30fc\u30b9 Python \u304b\u3089\u9694\u96e2\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<br \/>\r\n\u4eee\u60f3\u74b0\u5883\u306e\u4e2d\u304b\u3089\u4f7f\u308f\u308c\u308b\u3068\u3001<a href=\"https:\/\/pypi.org\/project\/pip\/\">pip<\/a>\u00a0 \u306e\u3088\u3046\u306a\u4e00\u822c\u7684\u306a\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30c4\u30fc\u30eb\u306f\u660e\u793a\u7684\u306b\u6307\u5b9a\u3057\u306a\u304f\u3066\u3082\u4eee\u60f3\u74b0\u5883\u306b Python \u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002&#8221;<\/span><\/p>\r\n<\/blockquote>\r\n<p>\u4e0b\u8a18\u30ea\u30f3\u30af\u306ePython\u306eDocument\u306b\u66f8\u3044\u3066\u308b\u901a\u308a\u3067\u3059\uff01<\/p>\r\n<p>[blogcard url=&#8221;https:\/\/docs.python.org\/ja\/3\/library\/venv.html&#8221;]<\/p>\r\n<p><!-- notionvc: 0c0686bb-03bf-4044-9f99-f160e472ec88 --><\/p>\n\n<h2>\u306a\u305c\u3084\u308b\u306e\u304b<\/h2>\n<p><span style=\"font-size: 14pt;\"><strong>\u4f9d\u5b58\u95a2\u4fc2\u306e\u885d\u7a81\u56de\u907f<\/strong>:<br \/>\r\n\u7570\u306a\u308b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u7570\u306a\u308b\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u5b89\u5168\u306b\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\"><strong>\u958b\u767a\u74b0\u5883\u306e\u4e00\u8cab\u6027<\/strong>:<br \/>\r\n\u65b0\u3057\u3044\u958b\u767a\u8005\u304c\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u53c2\u52a0\u3059\u308b\u969b\u3001<strong>venv<\/strong>\u3092\u4f7f\u3063\u3066\u7c21\u5358\u306b\u5fc5\u8981\u306a\u74b0\u5883\u3092\u518d\u73fe\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\"><strong>\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u306e\u5bb9\u6613\u6027<\/strong>:<br \/>\r\n\u4eee\u60f3\u74b0\u5883\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u672c\u756a\u74b0\u5883\u3078\u306e\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u304c\u3088\u308a\u4e88\u6e2c\u53ef\u80fd\u3067\u5b89\u5168\u306b\u306a\u308a\u307e\u3059\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\"><strong>\u30c4\u30fc\u30eb\u3068\u306e\u4e92\u63db\u6027<\/strong>:<br \/>\r\n<strong>venv<\/strong>\u306fPython\u306b\u7d44\u307f\u8fbc\u307e\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u8ffd\u52a0\u306e\u30c4\u30fc\u30eb\u3084\u8a2d\u5b9a\u306a\u3057\u3067\u5e83\u304f\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\r\n<p><!-- notionvc: 65b8783e-aebf-4491-b14e-04a1f01581e5 --><\/p>\n\n<h2>\u4f7f\u3044\u65b9<\/h2>\n<p><span style=\"font-size: 14pt;\">Python\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u7f6e\u304d\u305f\u3044\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3001\u79fb\u52d5<\/span><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code><code class=\"language-bash\">mkdir python_sample\r\ncd python_sample<\/code><\/code><\/pre>\r\n<\/div>\r\n<p><span style=\"font-size: 14pt;\">venv\u3092\u4f5c\u6210(myenv\u306f\u4efb\u610f\u306e\u540d\u524d\u3067\u4f5c\u6210\u53ef\u80fd)<\/span><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>python3 -m venv myenv<\/code><\/pre>\r\n<\/div>\r\n<p><span style=\"font-size: 14pt;\">venv\u3092\u30a2\u30af\u30c6\u30a3\u30d9\u30fc\u30c8<\/span><\/p>\r\n<p>Mac\/Linux\u306e\u5834\u5408:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>source myenv\/bin\/activate<\/code><\/pre>\r\n<\/div>\r\n<p>Windows\u306e\u5834\u5408:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>.\\\\myenv\\\\Scripts\\\\activate<\/code><\/pre>\r\n<\/div>\r\n<p><span style=\"font-size: 14pt;\">venv\u304c\u30a2\u30af\u30c6\u30a3\u30d9\u30fc\u30c8\u3055\u308c\u305f\u72b6\u614b\u3067\u3001Python\u30d5\u30a1\u30a4\u30eb\u3092\u7de8\u96c6\u30fb\u5b9f\u884c\u3057\u307e\u3059\u3002<\/span><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>python_sample\/\r\n\u2502\r\n\u251c\u2500\u2500 myenv\/                 # \u4eee\u60f3\u74b0\u5883\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\r\n\u2502\r\n\u251c\u2500\u2500 my_script.py           # Python\u30b9\u30af\u30ea\u30d7\u30c8\r\n\u251c\u2500\u2500 another_script.py      # \u5225\u306ePython\u30b9\u30af\u30ea\u30d7\u30c8\r\n\u2502\r\n\u2514\u2500\u2500 requirements.txt       # \u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30ea\u30b9\u30c8\r\n<\/code><\/pre>\r\n<\/div>\r\n<p><span style=\"font-size: 14pt;\">\u4f5c\u696d\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001\u4eee\u60f3\u74b0\u5883\u3092\u30c7\u30a3\u30a2\u30af\u30c6\u30a3\u30d9\u30fc\u30c8\u3057\u307e\u3059\u3002<\/span><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>deactivate<\/code><\/pre>\r\n<\/div>\r\n<p><!-- notionvc: f8549114-f756-465a-b854-fde305c032ac --><\/p>\n\n<h2>\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h2>\n<p><span style=\"font-size: 14pt;\"><strong>\u72ec\u7acb\u3057\u305f\u74b0\u5883\u306e\u5229\u7528<\/strong>: <br \/>\r\n\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3054\u3068\u306b\u72ec\u7acb\u3057\u305f\u74b0\u5883\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u3001\u4f9d\u5b58\u95a2\u4fc2\u306e\u885d\u7a81\u3092\u9632\u304e\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u518d\u73fe\u6027\u3092\u9ad8\u3081\u307e\u3059\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\"><strong><code>requirements.txt<\/code>\u306e\u4f7f\u7528<\/strong>: <br \/>\r\n<code>pip freeze &gt; requirements.txt<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001\u73fe\u5728\u306e\u74b0\u5883\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u305d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u30ea\u30b9\u30c8\u30a2\u30c3\u30d7\u3057\u3001<code>pip install -r requirements.txt<\/code>\u3067\u7c21\u5358\u306b\u518d\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\"><strong>\u958b\u767a\u3068\u672c\u756a\u306e\u74b0\u5883\u5206\u96e2<\/strong>: <br \/>\r\n\u958b\u767a\u74b0\u5883\u3068\u672c\u756a\u74b0\u5883\u3092\u5206\u3051\u308b\u3053\u3068\u3067\u3001\u4e88\u671f\u305b\u306c\u30a8\u30e9\u30fc\u3084\u885d\u7a81\u3092\u9632\u304e\u307e\u3059\u3002<\/span><\/p>\r\n<p><!-- notionvc: 0034939f-5083-4a92-a5a3-1810d7dc4b0e --><\/p>\n\n<h2>\u7d42\u308f\u308a\u306b<\/h2>\n<p>Python\u306e<span data-token-index=\"1\" spellcheck=\"false\" class=\"notion-enable-hover\">venv<\/span>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306f\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u7ba1\u7406\u3068\u958b\u767a\u30d7\u30ed\u30bb\u30b9\u306e\u52b9\u7387\u5316\u306b\u304a\u3044\u3066\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002<span data-token-index=\"3\" spellcheck=\"false\" class=\"notion-enable-hover\">venv<\/span>\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u4f9d\u5b58\u95a2\u4fc2\u306e\u885d\u7a81\u3092\u907f\u3051\u3001\u958b\u767a\u74b0\u5883\u306e\u4e00\u8cab\u6027\u3092\u4fdd\u3061\u3001\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u3092\u5bb9\u6613\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u30d6\u30ed\u30b0\u3092\u901a\u3058\u3066\u3001<span data-token-index=\"5\" spellcheck=\"false\" class=\"notion-enable-hover\">venv<\/span>\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u304b\u3089\u3001\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u307e\u3067\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002 \u5f53\u30d6\u30ed\u30b0\u304c\u3001\u3042\u306a\u305f\u306ePython\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u304a\u3051\u308b<span data-token-index=\"7\" spellcheck=\"false\" class=\"notion-enable-hover\">venv<\/span>\u306e\u7406\u89e3\u3068\u6d3b\u7528\u306b\u5f79\u7acb\u3064\u3053\u3068\u304c\u3067\u304d\u308c\u3070\u5e78\u3044\u3067\u3059<span data-token-index=\"9\" class=\"discussion-id-6d00b41e-2731-479c-992f-98bae63ebac6 notion-enable-hover\">\uff01<\/span><!-- notionvc: 02da9cb5-da00-419a-ae9f-d2d654e09a19 --><\/p>\n\n<h2>\u53c2\u7167<\/h2>\n<p>[blogcard url=&#8221;https:\/\/docs.python.org\/ja\/3\/library\/venv.html&#8221;]<\/p>\r\n<p>[blogcard url=&#8221;https:\/\/qiita.com\/fiftystorm36\/items\/b2fd47cf32c7694adc2e&#8221;]<\/p>\r\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Python\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u304a\u3044\u3066\u3001\u7570\u306a\u308b\u4f9d\u5b58\u95a2\u4fc2\u9593\u3067\u306e\u885d\u7a81\u3092\u907f\u3051\u3001\u958b\u767a\u74b0\u5883\u3092\u4e00\u8cab\u3055\u305b\u308b\u3053\u3068\u306f\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u6210\u529f\u306b\u4e0d\u53ef\u6b20\u3067\u3059\u3002Python\u306evenv\u306f\u3001\u3053\u306e\u3088\u3046\u306a\u554f\u984c\u306b\u5bfe\u51e6\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3042\u308a\u3001\u958b\u767a\u8005\u304c\u30d7\u30ed\u30b8\u30a7\u30af [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":4639,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","swell_btn_cv_data":"","footnotes":"","_wp_rev_ctl_limit":""},"categories":[1246],"tags":[331,39,27,565],"class_list":["post-4638","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-infrastructure","tag-python","tag-39","tag-27","tag-565"],"_links":{"self":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/4638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/comments?post=4638"}],"version-history":[{"count":0,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/4638\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media\/4639"}],"wp:attachment":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media?parent=4638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/categories?post=4638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/tags?post=4638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}