{"id":173469,"date":"2020-03-10T10:00:25","date_gmt":"2020-03-10T02:00:25","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=173469"},"modified":"2020-02-27T14:59:10","modified_gmt":"2020-02-27T06:59:10","slug":"python-virtualenv-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-virtualenv-linux.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdpython\u865a\u62df\u73af\u5883 virtualenv\u7684\u4f7f\u7528"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nvirtualenv\u662f\u4e00\u4e2a\u521b\u5efa\u9694\u7edd\u7684Python\u73af\u5883\u7684\u5de5\u5177\u3002\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86python\u865a\u62df\u73af\u5883 virtualenv\u7684\u7b80\u5355\u4f7f\u7528\uff0c\u672c\u6587\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u501f\u9274\u4ef7\u503c,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
virtualenv\u662f\u4ec0\u4e48\uff1f<\/strong><\/span><\/div>\n

virtualenv\u662f\u4e00\u4e2a\u521b\u5efa\u9694\u7edd\u7684Python\u73af\u5883\u7684\u5de5\u5177\u3002<\/p>\n

\u4e3a\u4ec0\u4e48\u8981\u521b\u5efa\u865a\u62df\u73af\u5883\uff1f<\/strong><\/span><\/div>\n

\u5b83\u89e3\u51b3\u4e86\u201c\u9879\u76eeX\u4f9d\u8d56\u4e8e\u7248\u672c1.x\uff0c\u800c\u9879\u76eeY\u9700\u8981\u9879\u76ee4.x\u201d\u7684\u4e24\u96be\u95ee\u9898\uff0c\u800c\u4e14\u4f7f\u4f60\u7684\u5168\u5c40site-packages\u76ee\u5f55\u4fdd\u6301\u5e72\u51c0\u548c\u53ef\u7ba1\u7406\u3002<\/p>\n

\u7b80\u4ecb<\/strong><\/span><\/div>\n

\u9694\u79bb\u4e0d\u540c\u7684python\u73af\u5883\uff0c\u5982\u6709\u70b9\u9879\u76ee\u7528Django1.11\u800c\u6709\u7684\u9879\u76ee\u7528Django2.0\uff0c\u4e3a\u4e86\u9632\u6b62\u4e0d\u65ad\u5730\u91cd\u65b0\u5728\u5168\u5c40\u73af\u5883\u4e2d\u53cd\u590d\u5b89\u88c5\u4e0d\u540c\u7248\u672c\u7684Django\uff0c\u53ef\u4ee5\u91c7\u7528\u4e24\u4e2a\u865a\u62df\u73af\u5883\u3002<\/p>\n

\u8fd9\u6837\u65e2\u4fdd\u8bc1\u4e86\u4e24\u4e2a\u73af\u5883\u4e4b\u95f4\u7684\u9694\u79bb\uff0c\u4e5f\u4e0d\u4f1a\u6c61\u67d3\u5168\u5c40\u73af\u5883\uff0c\u4fdd\u8bc1\u5168\u5c40\u73af\u5883\u7684\u5e72\u51c0<\/p>\n

\u5b89\u88c5virtualenv\u6a21\u5757<\/strong><\/span><\/div>\n
$ pip3 install virtualenv -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\/<\/pre>\n
\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/span><\/div>\n

\u5207\u5230\u60f3\u8981\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u8def\u5f84\u4e0b\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5<\/p>\n

$ virtualenv envname # \u521b\u5efa\u4e00\u4e2a\u540d\u5b57\u4e3aenvname\u7684\u865a\u62df\u73af\u5883\r\n$ virtualenv -p python2 envname # \u5982\u679c\u5b89\u88c5\u4e86\u591a\u4e2apython\u7248\u672c\uff0c\u5982py2\u548cpy3\uff0c\u9700\u8981\u6307\u5b9a\u4f7f\u7528\u54ea\u4e2a\u521b\u5efa\u865a\u62df\u73af\u5883<\/pre>\n
\u542f\u505c\u865a\u62df\u73af\u5883<\/strong><\/span><\/div>\n
\r\n# \u8fdb\u5165\u865a\u62df\u73af\u5883\u6587\u4ef6\r\ncd envname\r\n# \u8fdb\u5165\u76f8\u5173\u7684\u542f\u52a8\u6587\u4ef6\u5939\r\ncd Scripts\r\nactivate # \u542f\u52a8\u865a\u62df\u73af\u5883\r\ndeactivate # \u9000\u51fa\u865a\u62df\u73af\u5883<\/pre>\n
\u865a\u62df\u73af\u5883\u4e0b\u7684\u64cd\u4f5c<\/strong><\/span><\/div>\n
\r\n# \u5728\u865a\u62df\u73af\u5883\u4e0b\u67e5\u770b\u5f53\u524dpython\u7248\u672c\r\npython -V\r\n# \u5728\u865a\u62df\u73af\u5883\u4e0b\u67e5\u770b\u5f53\u524dpip\u7248\u672c\r\npip -V\r\n# \u67e5\u770b\u5f53\u524d\u865a\u62df\u73af\u5883\u5b89\u88c5\u7684\u6a21\u5757\r\npip list\r\n# \u4e8e\u865a\u62df\u73af\u5883\u4e0b\u5b89\u88c5\u6a21\u5757\r\npip install module_name<\/pre>\n

\u4e8e\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u7684\u6a21\u5757\u7684\u9ed8\u8ba4\u8def\u5f84\u5982\u4e0b<\/p>\n

$\u865a\u62df\u73af\u5883\u8def\u5f84\\Lib\\site-packages\\<\/pre>\n
pycharm\u5f15\u7528\u8be5\u865a\u62df\u73af\u5883<\/strong><\/span><\/div>\n

\u76f4\u63a5\u5728pycharm\u4e2d\u9009\u62e9\u89e3\u91ca\u5668\u7684\u65f6\u5019\u9009\u62e9\u8be5\u865a\u62df\u73af\u5883\u4e0b\u7684python\u89e3\u91ca\u5668\u5373\u53ef<\/p>\n

\u82e5pycharm\u76f4\u63a5\u6253\u5f00\u8be5\u865a\u62df\u73af\u5883\u7684\u6587\u4ef6\u5939\uff0c\u5219\u8be5\u865a\u62df\u73af\u5883\u4f1a\u5904\u4e8e\u6fc0\u6d3b\u72b6\u6001(\u53ef\u5728pycharm\u7684Terminal\u4e2d\u786e\u8ba4)<\/p>\n

\u5982\u4f55\u901a\u8fc7\u8be5\u865a\u62df\u73af\u5883\u521b\u5efaDjango\u9879\u76ee<\/p>\n

\u5207\u6362\u5230\u65b0\u5efa\u597d\u7684\u865a\u62df\u73af\u5883\u76ee\u5f55\u5e76\u6fc0\u6d3b\u8be5\u865a\u62df\u73af\u5883\uff0c<\/p>\n

\u5728\u8be5\u865a\u62df\u73af\u5883\u5185(\u6fc0\u6d3b\u72b6\u6001\u4e0b)\uff0c\u6267\u884cdjango-admin startproject Project_name .\uff0c\u5c31\u4f1a\u5728\u5f53\u524d\u865a\u62df\u73af\u5883\u6839\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2aDjango\u9879\u76ee\u7684\u6587\u4ef6\u5939<\/p>\n

\u5220\u9664\u865a\u62df\u73af\u5883<\/strong><\/span><\/div>\n

\u76f4\u63a5\u5220\u9664\u8be5\u6587\u4ef6\u5939\u5373\u53ef<\/p>\n

virtualenvwrapper<\/strong><\/span><\/div>\n

\u539f\u751f\u7684virtualenv\u6a21\u5757\u5728\u5bf9\u865a\u62df\u73af\u5883\u7684\u64cd\u4f5c\u4e0a\u7565\u5fae\u7e41\u7410\uff0cvirtualenvwrapper\u662f\u5bf9\u5b83\u7684\u5c01\u88c5\u7248\u672c\uff0c\u5728\u64cd\u4f5c\u4e0a\u65b9\u4fbf\u4e86\u5f88\u591a\uff0c\u5982\u901a\u8fc7rmvirtualenv venvName\u6765\u5220\u9664\u67d0\u4e2a\u865a\u62df\u73af\u5883<\/p>\n

pip install virtualenvwrapper # \u8fd9\u662f\u5bf9virtualenv\u7684\u5c01\u88c5\u7248\u672c\uff0c\u4e00\u5b9a\u8981\u5728virtualenv\u540e\u5b89\u88c5<\/pre>\n
\u603b\u7ed3<\/strong><\/span><\/div>\n

\u4ee5\u4e0a\u6240\u8ff0\u662f\u5c0f\u7f16\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684python\u865a\u62df\u73af\u5883 virtualenv\u7684\u7b80\u5355\u4f7f\u7528\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

virtualenv\u662f\u4e00\u4e2a\u521b\u5efa\u9694\u7edd\u7684Python\u73af\u5883\u7684\u5de5\u5177\u3002 \u5b83\u89e3\u51b3\u4e86\u201c\u9879\u76eeX\u4f9d\u8d56\u4e8e\u7248\u672c1.x\uff0c\u800c\u9879\u76eeY\u9700\u8981\u9879 […]<\/p>\n","protected":false},"author":1482,"featured_media":160637,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-173469","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/173469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=173469"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/173469\/revisions"}],"predecessor-version":[{"id":173473,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/173469\/revisions\/173473"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/160637"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=173469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=173469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=173469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}