{"id":62,"date":"2019-10-26T12:49:00","date_gmt":"2019-10-26T12:49:00","guid":{"rendered":"https:\/\/www.wangliguang.cn\/?p=62"},"modified":"2019-10-26T12:49:00","modified_gmt":"2019-10-26T12:49:00","slug":"linux%e4%b8%ad%e5%ae%89%e8%a3%85tensorflow%e6%95%99%e7%a8%8b-ubuntu18-04%e5%ae%89%e8%a3%85tensorflow%e6%95%99%e7%a8%8b-%e4%b8%80%e6%ad%a5%e4%b8%80%e6%ad%a5%e5%ae%8c%e5%85%a8%e7%89%88%ef%bc%81","status":"publish","type":"post","link":"https:\/\/wangliguang.cn\/?p=62","title":{"rendered":"Linux\u4e2d\u5b89\u88c5TensorFlow\u6559\u7a0b-Ubuntu18.04\u5b89\u88c5TensorFlow\u6559\u7a0b-\u4e00\u6b65\u4e00\u6b65\u5b8c\u5168\u7248\uff01"},"content":{"rendered":"<h2>\u4e00\u3001\u6240\u9700\u5de5\u5177<\/h2>\n<p>Ubuntu\u7cfb\u7edf\uff08\u7248\u672c16.04\u53ca\u4ee5\u4e0a\uff0c\u4f8b\u598218.04\uff09<\/p>\n<h2><a id=\"_2\"><\/a>\u4e8c\u3001\u8bf4\u660e<\/h2>\n<p>\u672c\u6559\u7a0b\u91c7\u7528pip\u5b89\u88c5TensorFlow\uff0c\u800c\u4e14\u91c7\u7528\u8c37\u6b4c\u63a8\u8350\u7684Create a virtual environment (recommended)\u65b9\u6cd5\u5b89\u88c5\uff0c\u4f7f\u5f97\u5305\u5b89\u88c5\u4e0e\u7cfb\u7edf\u9694\u79bb\uff0c\u9632\u6b62\u4ea7\u751f\u6df7\u4e71<\/p>\n<h2><a id=\"_4\"><\/a>\u4e09\u3001\u5b89\u88c5\u6b65\u9aa4<\/h2>\n<p>1\u3001\u9996\u5148\u68c0\u67e5\u662f\u5426\u6ee1\u8db3\u4e86\u6240\u9700\u7684\u73af\u5883\uff0c\u8f93\u5165\u4e0b\u9762\u4e09\u4e2a\u547d\u4ee4\uff1a<\/p>\n<pre><code>python3 --version\npip3 --version\nvirtualenv --version\n<\/code><\/pre>\n<p>2 \u3001<strong>\u5982\u679c\u7248\u672c\u53f7\u6b63\u786e\u8f93\u51fa\uff0c\u8868\u793a\u90fd\u5b89\u597d\u4e86\uff0c\u76f4\u63a5\u770b\u7b2c4\u6b65<\/strong>\uff0c\u5426\u5219\u7ee7\u7eed\u5f80\u4e0b\u770b\u7b2c3\u6b65\u3002<br \/>\n3\u3001\u5982\u679c\u6ca1\u5b89\u597d\uff0c\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5c06python3\u3001pip3\u548cvirtualenv\u5b89\u597d\u3002<\/p>\n<pre><code>sudo apt update\nsudo apt install python3-dev python3-pip\nsudo pip3 install -U virtualenv  # system-wide install\n<\/code><\/pre>\n<p>4\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/p>\n<pre><code>virtualenv --system-site-packages -p python3 .\/venv\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff0c <strong>.\/venv<\/strong>\u8868\u793a\u7684\u662f\u4f60\u7684\u865a\u62df\u73af\u5883\u7684\u4f4d\u7f6e\uff0c\u8bf7\u6539\u6210\u4f60\u60f3\u521b\u5efa\u7684\u4f4d\u7f6e\u3002\uff08\u8fd9\u91cc\u6211\u4eec\u521b\u5efa\u5728\u5f53\u524d\u76ee\u5f55\u7684venv\u6587\u4ef6\u5939\u4e0b\uff09<br \/>\n5\u3001\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002<\/p>\n<pre><code>source .\/venv\/bin\/activate\n<\/code><\/pre>\n<p><strong>\u5982\u679c\u4f60\u524d\u9762\u521b\u5efa\u865a\u62df\u73af\u5883\u65f6\u6539\u4e86\u8def\u5f84\uff0c\u8fd9\u91cc\u4e5f\u8981\u6539\u6210\uff1a\u4f60\u7684\u865a\u62df\u73af\u5883\u7684\u8def\u5f84\/bin\/activate<\/strong><br \/>\n\u6b64\u65f6\uff0c\u4f60\u7684shell\u524d\u9762\u90fd\u4f1a\u4ee5\uff08venv\uff09\u5f00\u5934\u4e86\u3002<br \/>\n6\u3001\u66f4\u65b0pip\u3002\u6ce8\u610f\uff0c\u7531\u4e8e\u6211\u4eec\u662f\u5728\u865a\u62df\u73af\u5883\u91cc\u64cd\u4f5c\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u8bbe\u7f6e\uff0c\u90fd\u662f\u5728\u865a\u62df\u73af\u5883\u91cc\u8fdb\u884c\u7684\u3002<\/p>\n<pre><code>pip install --upgrade pip\npip list  # show packages installed within the virtual environment\n<\/code><\/pre>\n<p>7\u3001\u5b89\u88c5TensorFlow\u3002\u4ee5CPU\u7248\u672c\u4e3a\u4f8b\uff0c\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u3002<\/p>\n<pre><code>pip install --upgrade tensorflow\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u60f3\u5b89\u88c5\u5176\u4ed6\u7248\u672c\uff0c\u6839\u636e\u4e0b\u9762\u7684\u8bf4\u660e\u9009\u4e00\u4e2a\u5c31\u884c\u4e86\uff1a<\/p>\n<blockquote><p>\nChoose one of the following TensorFlow packages to install from PyPI:<br \/>\ntensorflow \u2014Latest stable release for CPU-only (recommended for beginners)<br \/>\ntensorflow-gpu \u2014Latest stable release with GPU support (Ubuntu and Windows)<br \/>\ntf-nightly \u2014Preview build (unstable). Ubuntu and Windows include GPU support.\n<\/p><\/blockquote>\n<p>8\u3001\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6d4b\u8bd5\u5b89\u88c5\u7ed3\u679c\u3002\u8f93\u5165\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code>python -c \"import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))\"\n<\/code><\/pre>\n<p>\u5982\u679c<strong>\u8f93\u51fa\u7684\u6700\u540e\u4e00\u884c\u662ftf.tensor\u4ec0\u4e48\u4ec0\u4e48<\/strong>\uff0c\u606d\u559c\u4f60\u5b89\u88c5\u5b8c\u6210\uff01<br \/>\n9\u3001\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/p>\n<pre><code>deactivate\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff0c\u56e0\u4e3a\u6211\u4eec\u662f\u5728\u865a\u62df\u73af\u5883\u91cc\u5b89\u88c5\u7684TensorFlow\uff0c\u6240\u4ee5\uff0c<strong>\u4f60\u5fc5\u987b\u5728\u4f7f\u7528TensorFlow\u524d\u8fdb\u5165\u865a\u62df\u73af\u5883\uff0c\u5728\u7528\u5b8cTensorFlow\u540e\u518d\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong>\uff0c<strong>\u5426\u5219TensorFlow\u662f\u65e0\u6cd5\u4f7f\u7528\u7684\u3002\u6240\u4ee5\u8bf7\u4ed4\u7ec6\u9605\u8bfb\u4e0b\u9762\u7684\u6587\u5b57<\/strong><\/p>\n<h2><a id=\"_65\"><\/a>\u56db\u3001\u6ce8\u610f\u4e8b\u9879<\/h2>\n<p>\u56e0\u4e3a\u6211\u4eec\u662f\u5728\u865a\u62df\u73af\u5883\u91cc\u5b89\u88c5\u7684TensorFlow\uff0c\u6240\u4ee5\uff0c<strong>\u4f60\u5fc5\u987b\u5728\u4f7f\u7528TensorFlow\u524d\u8fdb\u5165\u865a\u62df\u73af\u5883\uff0c\u5728\u7528\u5b8cTensorFlow\u540e\u518d\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong>\uff0c<strong>\u5426\u5219TensorFlow\u662f\u65e0\u6cd5\u4f7f\u7528\u7684\u3002<\/strong><br \/>\n<strong>\u8fdb\u5165\u865a\u62df\u73af\u5883\u7684\u547d\u4ee4\uff1a<\/strong><\/p>\n<pre><code>source .\/venv\/bin\/activate\n<\/code><\/pre>\n<p><strong>\u5982\u679c\u4f60\u524d\u9762\u521b\u5efa\u865a\u62df\u73af\u5883\u65f6\u6539\u4e86\u8def\u5f84\uff0c\u8fd9\u91cc\u4e5f\u8981\u6539\u6210\uff1a\u4f60\u7684\u865a\u62df\u73af\u5883\u7684\u8def\u5f84\/bin\/activate<\/strong><br \/>\n\u8fdb\u5165\u865a\u62df\u73af\u5883\u540e\u4f1a\uff0cshell\u4f1a\u53d8\u6210\u7c7b\u4f3c<img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/20191026203654696.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\">\u5f00\u5934<br \/>\n\u9000\u51fa\u865a\u62df\u73af\u5883\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code>deactivate\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6240\u9700\u5de5\u5177 Ubuntu\u7cfb\u7edf\uff08\u7248\u672c16.04\u53ca\u4ee5\u4e0a\uff0c\u4f8b\u598218.04\uff09 \u4e8c\u3001\u8bf4\u660e \u672c\u6559\u7a0b\u91c7\u7528pip\u5b89\u88c5Tens&hellip; <a href=\"https:\/\/wangliguang.cn\/?p=62\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">Linux\u4e2d\u5b89\u88c5TensorFlow\u6559\u7a0b-Ubuntu18.04\u5b89\u88c5TensorFlow\u6559\u7a0b-\u4e00\u6b65\u4e00\u6b65\u5b8c\u5168\u7248\uff01<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,15,19],"tags":[31,37,41],"class_list":["post-62","post","type-post","status-publish","format-standard","hentry","category-linux","category-15","category-19","tag-linux","tag-37","tag-41"],"_links":{"self":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=62"}],"version-history":[{"count":0,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/62\/revisions"}],"wp:attachment":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}