{"id":1756,"date":"2017-05-21T21:47:08","date_gmt":"2017-05-21T13:47:08","guid":{"rendered":"https:\/\/blog.vimge.com\/?p=1756"},"modified":"2017-06-06T08:45:55","modified_gmt":"2017-06-06T00:45:55","slug":"python-virtualenv","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/python\/python-virtualenv.html","title":{"rendered":"Python\u865a\u62df\u5316\u73af\u5883\u5de5\u5177\uff1aVirtualenv"},"content":{"rendered":"

Virtualenv\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n

Virtualenv\u662fPython\u4e0b\u9762\u521b\u5efa\u9694\u79bb\u73af\u5883\u7684\u865a\u62df\u5316\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u9879\u76ee\u7684\u8fd0\u8425\u8fd0\u884c\u73af\u5883\u5c01\u88c5\u5728\u4e00\u4e2a\u5b8c\u5168\u300e\u9694\u79bb\u300f\u7684\u73af\u5883\u91cc\uff0c\u548c\u5176\u4ed6\u9879\u76ee\u4e92\u4e0d\u5f71\u54cd\u3002<\/p>\n

Virtualenv\u89e3\u51b3\u4ec0\u4e48\u95ee\u9898\uff1f<\/strong><\/p>\n

\u4e0d\u540c\u9879\u76ee\u53ef\u80fd\u4f9d\u8d56\u540c\u4e00\u4e2a\u5305\u7684\u4e0d\u540c\u7248\u672c\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u6211\u4eec\u4f1a\u5c06\/usr\/lib\/python2.7\/site-packages<\/span><\/tt>\u00a0\u8def\u5f84\uff0c\u9879\u76ee\u6267\u884c\u8fc7\u7a0b\u4e2d\u5c06\u4f1a\u4ea7\u751f\u51b2\u7a81\uff0c\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u5404\u9879\u76ee\u95f4\u5b8c\u5168\u9694\u79bb\u7684\u73af\u5883\uff0c\u8fd9\u5c31\u662fVirtualenv\u8981\u89e3\u51b3\u7684\u95ee\u9898.<\/p>\n

Virtualenv\u7684\u8fd0\u884c\u673a\u5236<\/strong><\/p>\n

\u4e00\u822c\u6211\u4eec\u4f1a\u5728\u9879\u76ee\u6839\u76ee\u5f55\u521b\u5efa\u4e00\u4e2avenv\u76ee\u5f55\uff08\u540d\u5b57\u53ef\u4ee5\u81ea\u5b9a\u4e49\uff09\uff0c\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u65f6\u5019\u6307\u5b9a\u521a\u624d\u7684\u76ee\u5f55\uff0cVirtualenv\u5c06\u4f1a\u5728\u5f53\u524d\u7684\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u5305\u542b\u4e86Python\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4ee5\u53ca pip \u5e93\u7684\u4e00\u4efd\u62f7\u8d1d\uff0c\u8fd9\u6837\u5c31\u80fd\u5b89\u88c5\u5176\u4ed6\u5305\u4e86\uff0cvenv\u76ee\u5f55\u4e0b\u9762\u5305\u542b\u5b8c\u6574\u7684\u865a\u62df\u73af\u5883\uff0c\u5728\u865a\u62df\u73af\u5883\u4e0b\u9762\u6267\u884cpip\u547d\u4ee4\u5b89\u88c5\u65b0\u7684\u5305\u4e5f\u53ea\u4f1a\u5b89\u88c5\u5230venv\u5b50\u76ee\u5f55\u4e0b\u5728\uff0c \u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40\u7684\u5176\u4ed6\u9879\u76ee\u3002<\/p>\n

\u4e3a\u9879\u76ee\u521b\u5efa\u865a\u62df\u73af\u5883<\/p>\n

$ virtualenv venv<\/p><\/blockquote>\n

\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/p>\n

$ source venv\/bin\/activate<\/p><\/blockquote>\n

\u4f60\u4f1a\u53d1\u73b0\u7ec8\u7aef\u547d\u4ee4\u884c\u524d\u9762\u5e26\u4e86\u4e2a\u62ec\u53f7\u548c\u521a\u624d\u7684\u865a\u62df\u73af\u5883\u76ee\u5f55\u540d\u79f0\uff0c\u4ece\u73b0\u5728\u8d77\uff0c\u4efb\u4f55\u4f60\u4f7f\u7528pip\u5b89\u88c5\u7684\u5305\u5c06\u4f1a\u653e\u5728 \u00a0venv \u6587\u4ef6\u5939\u4e2d\uff0c\u4e0e\u5168\u5c40\u5b89\u88c5\u7684Python\u9694\u7edd\u5f00\u3002<\/p>\n

\u8fdb\u5165\u865a\u62df\u73af\u5883\u540e\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u4f60\u5c31\u53ef\u4ee5\u7406\u89e3Virtualenv\u505a\u4e86\u4ec0\u4e48<\/p>\n

(venv) $ which python<\/p>\n

\u9879\u76ee\u76ee\u5f55\/venv\/bin\/python<\/p><\/blockquote>\n

Python\u7684\u8def\u5f84\u662f\u76f8\u5bf9\u9879\u76ee\u6839\u76ee\u4e0b\u9762\u7684venv\u76ee\u5f55\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u91cc\u9762\u662f\u4e00\u4e2a\u5b8c\u6574\u7684python\u73af\u5883\u62f7\u8d1d\uff0c\u65b0\u5b89\u88c5\u7684\u5305\u4e5f\u662f\u5b89\u88c5\u5728venv\u5b50\u76ee\u5f55\u4e0b\u9762.<\/p>\n

\u4f7f\u7528\u540e\u53ef\u4ee5\u53d1\u73b0 virtualenv \u662f\u4e00\u4e2a\u975e\u5e38\u8f7b\u91cf\u5316\u7684\u5de5\u5177\uff0c\u5bf9\u7cfb\u7edf\u73af\u5883\u57fa\u672c\u6ca1\u6709\u5f71\u54cd\uff0c\u53ea\u662f\u65b0\u5efa\u4e00\u4e2a\u76ee\u5f55\uff0c\u8981\u5220\u9664\u7684\u8bdd\u4e5f\u53ea\u9700\u79fb\u9664 venv \u76ee\u5f55\u5373\u53ef\u3002<\/p>\n

 <\/p>\n

 <\/p>\n

\u9879\u76ee\u5b98\u7f51\uff1ahttps:\/\/pypi.python.org\/pypi\/virtualenv<\/em><\/p>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

Virtualenv\u662f\u4ec0\u4e48\uff1f Virtualenv\u662fPython\u4e0b\u9762\u521b\u5efa\u9694\u79bb\u73af\u5883\u7684\u865a\u62df\u5316\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u9879\u76ee […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[155],"tags":[154],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1756"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1756"}],"version-history":[{"count":4,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1756\/revisions"}],"predecessor-version":[{"id":1760,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1756\/revisions\/1760"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}