在 macOS 中安装 TensorFlow 1g

tensorflow 需要多大空间

pip install tensorflow

pip install tensorflow
Looking in indexes: https://pypi.douban.com/simple/
Collecting tensorflow
  Downloading https://pypi.doubanio.com/packages/1a/c1/9c14df0625836af8ba6628585c6d3c3bf8f1e1101cafa2435eb28a776455/tensorflow-2.13.0-cp39-cp39-macosx_10_15_x86_64.whl (216.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 216.2/216.2 MB 938.0 kB/s eta 0:00:00
Collecting absl-py>=1.0.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/dd/87/de5c32fa1b1c6c3305d576e299801d8655c175ca9557019906247b994331/absl_py-1.4.0-py3-none-any.whl (126 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 126.5/126.5 kB 3.1 MB/s eta 0:00:00
Collecting astunparse>=1.6.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/2b/03/13dde6512ad7b4557eb792fbcf0c653af6076b81e5941d36ec61f7ce6028/astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting flatbuffers>=23.1.21 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/6f/12/d5c79ee252793ffe845d58a913197bfa02ae9a0b5c9bc3dc4b58d477b9e7/flatbuffers-23.5.26-py2.py3-none-any.whl (26 kB)
Collecting gast<=0.4.0,>=0.2.1 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/b6/48/583c032b79ae5b3daa02225a675aeb673e58d2cb698e78510feceb11958c/gast-0.4.0-py3-none-any.whl (9.8 kB)
Collecting google-pasta>=0.1.1 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/a3/de/c648ef6835192e6e2cc03f40b19eeda4382c49b5bafb43d88b931c4c74ac/google_pasta-0.2.0-py3-none-any.whl (57 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.5/57.5 kB 4.8 MB/s eta 0:00:00
Collecting h5py>=2.9.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/0a/02/c794b1e21ba76ceeb99e5c748240c2ade5bd39d57b2ff050784e6a660f2f/h5py-3.8.0-cp39-cp39-macosx_10_9_x86_64.whl (3.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 664.2 kB/s eta 0:00:00
Collecting libclang>=13.0.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/55/47/bbcdba9c08b2fd493648af7da2aeb55508d07aeac6010300bb5b57032ea8/libclang-16.0.0-py2.py3-none-macosx_10_9_x86_64.whl (26.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 26.7/26.7 MB 677.1 kB/s eta 0:00:00
Requirement already satisfied: numpy<=1.24.3,>=1.22 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from tensorflow) (1.22.3)
Collecting opt-einsum>=2.3.2 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/bc/19/404708a7e54ad2798907210462fd950c3442ea51acc8790f3da48d2bee8b/opt_einsum-3.3.0-py3-none-any.whl (65 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.5/65.5 kB 1.2 MB/s eta 0:00:00
Requirement already satisfied: packaging in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from tensorflow) (23.1)
Collecting protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/b5/eb/59e88dfdcc2ca55aaf067f9ff9289216e44ed659a1a5628382a374d40d99/protobuf-4.23.3-cp37-abi3-macosx_10_9_universal2.whl (400 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 400.3/400.3 kB 2.4 MB/s eta 0:00:00
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from tensorflow) (58.1.0)
Requirement already satisfied: six>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from tensorflow) (1.15.0)
Collecting termcolor>=1.1.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/67/e1/434566ffce04448192369c1a282931cf4ae593e91907558eaecd2e9f2801/termcolor-2.3.0-py3-none-any.whl (6.9 kB)
Requirement already satisfied: typing-extensions<4.6.0,>=3.6.6 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from tensorflow) (4.5.0)
Collecting wrapt>=1.11.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/b7/3d/9d3cd75f7fc283b6e627c9b0e904189c41ca144185fd8113a1a094dec8ca/wrapt-1.15.0-cp39-cp39-macosx_10_9_x86_64.whl (35 kB)
Collecting grpcio<2.0,>=1.24.3 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/97/b3/fb1dcedf39be0854403a28935f2c1e7e4025b3579801c7e91a1cac5b665c/grpcio-1.56.0-cp39-cp39-macosx_10_10_universal2.whl (8.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.9/8.9 MB 1.3 MB/s eta 0:00:00
Collecting tensorboard<2.14,>=2.13 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/67/f2/e8be5599634ff063fa2c59b7b51636815909d5140a26df9f02ce5d99b81a/tensorboard-2.13.0-py3-none-any.whl (5.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.6/5.6 MB 4.6 MB/s eta 0:00:00
INFO: pip is looking at multiple versions of tensorflow to determine which version is compatible with other requirements. This could take a while.
Collecting tensorflow
  Downloading https://pypi.doubanio.com/packages/8e/75/57ff7109b2bab5345e174350df33cb8cde26ef1e87d3935d2d1601288bee/tensorflow-2.12.1-cp39-cp39-macosx_10_15_x86_64.whl (230.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 230.1/230.1 MB 794.1 kB/s eta 0:00:00
Collecting jax>=0.3.15 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/91/06/00616821a40137a96ab8192473687dfbdc5dc87f6aa83c4f36630bc3f11f/jax-0.4.12.tar.gz (1.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 908.0 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting wrapt<1.15,>=1.11.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/d9/ab/3ba5816dd466ffd7242913708771d258569825ab76fd29d7fd85b9361311/wrapt-1.14.1-cp39-cp39-macosx_10_9_x86_64.whl (35 kB)
Collecting tensorboard<2.13,>=2.12 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/32/09/86e2ef3b4f4ec04bde0eca499325f291ae6b3313381d0666ee20b5b80c73/tensorboard-2.12.3-py3-none-any.whl (5.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.6/5.6 MB 4.3 MB/s eta 0:00:00
Collecting tensorflow-estimator<2.13,>=2.12.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/d1/e1/c3596da404e2c47561a2bb392397208925e65be6f61bd3081e630371d5e8/tensorflow_estimator-2.12.0-py2.py3-none-any.whl (440 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 440.7/440.7 kB 3.2 MB/s eta 0:00:00
Collecting keras<2.13,>=2.12.0 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/d5/80/34e55d7e3ed9cf18020929460f969de1bf82cf2f509c639b358ae2b25618/keras-2.12.0-py2.py3-none-any.whl (1.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 4.7 MB/s eta 0:00:00
Collecting tensorflow-io-gcs-filesystem>=0.23.1 (from tensorflow)
  Downloading https://pypi.doubanio.com/packages/54/a9/f692e98c381f86ad810e00e4eac0f1fc5a30ba6421db0472fea73a11ec6e/tensorflow_io_gcs_filesystem-0.32.0-cp39-cp39-macosx_10_14_x86_64.whl (1.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 957.1 kB/s eta 0:00:00
Requirement already satisfied: wheel<1.0,>=0.23.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from astunparse>=1.6.0->tensorflow) (0.37.1)
Collecting ml-dtypes>=0.1.0 (from jax>=0.3.15->tensorflow)
  Downloading https://pypi.doubanio.com/packages/e6/90/a2fc320d098a72b4c96f97b128bab7449dd479c704075b96bc86bb9e3be5/ml_dtypes-0.1.0-cp39-cp39-macosx_10_9_universal2.whl (317 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 317.9/317.9 kB 673.2 kB/s eta 0:00:00
Collecting scipy>=1.7 (from jax>=0.3.15->tensorflow)
  Downloading https://pypi.doubanio.com/packages/03/c3/5162f7d23a12c62cf0630f6cce20932f166fca7cb5513ed9af56b5618ba6/scipy-1.11.2-cp39-cp39-macosx_10_9_x86_64.whl (37.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 37.2/37.2 MB 1.2 MB/s eta 0:00:00
Collecting importlib-metadata>=4.6 (from jax>=0.3.15->tensorflow)
  Downloading https://pypi.doubanio.com/packages/30/bb/bf2944b8b88c65b797acc2c6a2cb0fb817f7364debf0675792e034013858/importlib_metadata-6.6.0-py3-none-any.whl (22 kB)
Collecting google-auth<3,>=1.6.3 (from tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/0d/77/4737ca3b929e95df9234827f7ddcf66199df2d96057ba9a98168957de7fa/google_auth-2.21.0-py2.py3-none-any.whl (182 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 182.1/182.1 kB 2.2 MB/s eta 0:00:00
Collecting google-auth-oauthlib<1.1,>=0.5 (from tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/4a/07/8d9a8186e6768b55dfffeb57c719bc03770cf8a970a074616ae6f9e26a57/google_auth_oauthlib-1.0.0-py2.py3-none-any.whl (18 kB)
Collecting markdown>=2.6.8 (from tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/9a/a1/1352b0e5a3c71a79fa9265726e2217f69df9fd4de0bcb5725cc61f62a5df/Markdown-3.4.3-py3-none-any.whl (93 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 93.9/93.9 kB 2.6 MB/s eta 0:00:00
Requirement already satisfied: requests<3,>=2.21.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from tensorboard<2.13,>=2.12->tensorflow) (2.28.2)
Collecting tensorboard-data-server<0.8.0,>=0.7.0 (from tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/3c/41/765bbe096ed6a8bb8f091c570505d0b15c4ab87c347ba61164cd1b391b51/tensorboard_data_server-0.7.0-py3-none-macosx_10_9_x86_64.whl (4.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.8/4.8 MB 4.5 MB/s eta 0:00:00
Collecting werkzeug>=1.0.1 (from tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/ba/d6/8040faecaba2feb84e1647af174b3243c9b90c163c7ea407820839931efe/Werkzeug-2.3.6-py3-none-any.whl (242 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 242.5/242.5 kB 6.7 MB/s eta 0:00:00
Collecting cachetools<6.0,>=2.0.0 (from google-auth<3,>=1.6.3->tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/a9/c9/c8a7710f2cedcb1db9224fdd4d8307c9e48cbddc46c18b515fefc0f1abbe/cachetools-5.3.1-py3-none-any.whl (9.3 kB)
Collecting pyasn1-modules>=0.2.1 (from google-auth<3,>=1.6.3->tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/cd/8e/bea464350e1b8c6ed0da3a312659cb648804a08af6cacc6435867f74f8bd/pyasn1_modules-0.3.0-py2.py3-none-any.whl (181 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 181.3/181.3 kB 1.7 MB/s eta 0:00:00
Collecting rsa<5,>=3.1.4 (from google-auth<3,>=1.6.3->tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/49/97/fa78e3d2f65c02c8e1268b9aba606569fe97f6c8f7c2d74394553347c145/rsa-4.9-py3-none-any.whl (34 kB)
Requirement already satisfied: urllib3<2.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from google-auth<3,>=1.6.3->tensorboard<2.13,>=2.12->tensorflow) (1.26.15)
Collecting requests-oauthlib>=0.7.0 (from google-auth-oauthlib<1.1,>=0.5->tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/6f/bb/5deac77a9af870143c684ab46a7934038a53eb4aa975bc0687ed6ca2c610/requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)
Collecting zipp>=0.5 (from importlib-metadata>=4.6->jax>=0.3.15->tensorflow)
  Downloading https://pypi.doubanio.com/packages/5b/fa/c9e82bbe1af6266adf08afb563905eb87cab83fde00a0a08963510621047/zipp-3.15.0-py3-none-any.whl (6.8 kB)
Requirement already satisfied: charset-normalizer<4,>=2 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests<3,>=2.21.0->tensorboard<2.13,>=2.12->tensorflow) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests<3,>=2.21.0->tensorboard<2.13,>=2.12->tensorflow) (3.4)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests<3,>=2.21.0->tensorboard<2.13,>=2.12->tensorflow) (2020.6.20)
Collecting MarkupSafe>=2.1.1 (from werkzeug>=1.0.1->tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/77/26/af46880038c6eac3832e751298f1965f3a550f38d1e9ddaabd674860076b/MarkupSafe-2.1.2-cp39-cp39-macosx_10_9_x86_64.whl (13 kB)
Collecting pyasn1<0.6.0,>=0.4.6 (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/14/e5/b56a725cbde139aa960c26a1a3ca4d4af437282e20b5314ee6a3501e7dfc/pyasn1-0.5.0-py2.py3-none-any.whl (83 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 83.9/83.9 kB 3.6 MB/s eta 0:00:00
Collecting oauthlib>=3.0.0 (from requests-oauthlib>=0.7.0->google-auth-oauthlib<1.1,>=0.5->tensorboard<2.13,>=2.12->tensorflow)
  Downloading https://pypi.doubanio.com/packages/7e/80/cab10959dc1faead58dc8384a781dfbf93cb4d33d50988f7a69f1b7c9bbe/oauthlib-3.2.2-py3-none-any.whl (151 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 151.7/151.7 kB 2.4 MB/s eta 0:00:00
Building wheels for collected packages: jax
  Building wheel for jax (pyproject.toml) ... done
  Created wheel for jax: filename=jax-0.4.12-py3-none-any.whl size=1498447 sha256=ad5dea1b5a274b333fc78d07890dfc3099845634d5aef21bb9d92f703ac57a00
  Stored in directory: /Users/cc/Library/Caches/pip/wheels/63/9c/97/d124a1f18880ec1c3f2d2fb9d417e30efc57b5259da3c639f9
Successfully built jax
Installing collected packages: libclang, flatbuffers, zipp, wrapt, termcolor, tensorflow-io-gcs-filesystem, tensorflow-estimator, tensorboard-data-server, scipy, pyasn1, protobuf, opt-einsum, oauthlib, ml-dtypes, MarkupSafe, keras, h5py, grpcio, google-pasta, gast, cachetools, astunparse, absl-py, werkzeug, rsa, requests-oauthlib, pyasn1-modules, importlib-metadata, markdown, jax, google-auth, google-auth-oauthlib, tensorboard, tensorflow
Successfully installed MarkupSafe-2.1.2 absl-py-1.4.0 astunparse-1.6.3 cachetools-5.3.1 flatbuffers-23.5.26 gast-0.4.0 google-auth-2.21.0 google-auth-oauthlib-1.0.0 google-pasta-0.2.0 grpcio-1.56.0 h5py-3.8.0 importlib-metadata-6.6.0 jax-0.4.12 keras-2.12.0 libclang-16.0.0 markdown-3.4.3 ml-dtypes-0.1.0 oauthlib-3.2.2 opt-einsum-3.3.0 protobuf-4.23.3 pyasn1-0.5.0 pyasn1-modules-0.3.0 requests-oauthlib-1.3.1 rsa-4.9 scipy-1.11.2 tensorboard-2.12.3 tensorboard-data-server-0.7.0 tensorflow-2.12.1 tensorflow-estimator-2.12.0 tensorflow-io-gcs-filesystem-0.32.0 termcolor-2.3.0 werkzeug-2.3.6 wrapt-1.14.1 zipp-3.15.0












安装 TensorFlow 2
我们在以下 64 位系统上测试过 TensorFlow 并且这些系统支持 TensorFlow:

Python 3.6–3.9
Ubuntu 16.04 或更高版本
Windows 7 或更高版本(含 C++ 可再发行软件包)
macOS 10.12.6 (Sierra) 或更高版本(不支持 GPU)

Requires the latest pip

pip install --upgrade pip

Current stable release for CPU and GPU

pip install tensorflow

Or try the preview build (unstable)

pip install tf-nightly

下载软件包
使用 Python 的 pip 软件包管理器安装 TensorFlow。

TensorFlow 2 软件包需要使用高于 19.0 的 pip 版本(对于 macOS 来说,则需要高于 20.3 的 pip 版本)。
官方软件包支持 Ubuntu、Windows 和 macOS。

有关支持 CUDA® 的卡,请参阅 GPU 指南。

阅读 pip 安装指南
运行 TensorFlow 容器
TensorFlow Docker 映像已经过配置,可运行 TensorFlow。Docker 容器可在虚拟环境中运行,是设置 GPU 支持的最简单方法。

docker pull tensorflow/tensorflow:latest # Download latest stable image
docker run -it -p 8888:8888 tensorflow/tensorflow:latest-jupyter # Start Jupyter server
阅读 Docker 安装指南
Google Colab:学习和使用 TensorFlow 的一种简单方法
无需安装,可直接在浏览器中使用 Colaboratory 运行 TensorFlow 教程。Colaboratory 是一个 Google 研究项目,旨在帮助传播机器学习知识和研究成果。它是一个 Jupyter 笔记本环境,不需要进行任何设置就可以使用,并且完全在云端运行。 阅读博文。

构建首个机器学习应用
创建和部署网页版和移动版 TensorFlow 模型。
Web 开发者
TensorFlow.js 是一个采用 WebGL 加速技术的 JavaScript 库,可用于在浏览器、Node.js、移动设备等平台上训练和部署机器学习模型。
移动开发者
TensorFlow Lite 是针对移动设备和嵌入式设备提供的精简解决方案。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。

-

Successfully
installed
MarkupSafe-2.1.2 absl-py-1.4.0 astunparse-1.6.3 cachetools-5.3.1 flatbuffers-23.5.26 gast-0.4.0 google-auth-2.21.0 google-auth-oauthlib-1.0.0 google-pasta-0.2.0 grpcio-1.56.0 h5py-3.8.0 importlib-metadata-6.6.0 jax-0.4.12 keras-2.12.0 libclang-16.0.0 markdown-3.4.3 ml-dtypes-0.1.0 oauthlib-3.2.2 opt-einsum-3.3.0 protobuf-4.23.3 pyasn1-0.5.0 pyasn1-modules-0.3.0 requests-oauthlib-1.3.1 rsa-4.9 scipy-1.11.2 tensorboard-2.12.3 tensorboard-data-server-0.7.0 tensorflow-2.12.1 tensorflow-estimator-2.12.0 tensorflow-io-gcs-filesystem-0.32.0 termcolor-2.3.0 werkzeug-2.3.6 wrapt-1.14.1 zipp-3.15.0

-

>>> import tensorflow as tf
2023-08-26 21:28:07.847547: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
>>> 

在这里插入图片描述

This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
tf.Tensor([[1. 2.]], shape=(1, 2), dtype=float32)

使用 pip 安装 TensorFlow

bookmark_border

TensorFlow 2 软件包现已推出
tensorflow:支持 CPU 和 GPU 的最新稳定版(适用于 Ubuntu 和 Windows)
tf-nightly:预览 build(不稳定)。Ubuntu 和 Windows 均包含 GPU 支持。
旧版 TensorFlow
对于 TensorFlow 1.x,CPU 和 GPU 软件包是分开的:

tensorflow1.15:仅支持 CPU 的版本
tensorflow-gpu
1.15:支持 GPU 的版本(适用于 Ubuntu 和 Windows)
系统要求
Python 3.6–3.9
若要支持 Python 3.9,需要使用 TensorFlow 2.5 或更高版本。
若要支持 Python 3.8,需要使用 TensorFlow 2.2 或更高版本。
pip 19.0 或更高版本(需要 manylinux2010 支持)
Ubuntu 16.04 或更高版本(64 位)
macOS 10.12.6 (Sierra) 或更高版本(64 位)(不支持 GPU)
macOS 要求使用 pip 20.3 或更高版本
Windows 7 或更高版本(64 位)
适用于 Visual Studio 2015、2017 和 2019 的 Microsoft Visual C++ 可再发行软件包
GPU 支持需要使用支持 CUDA® 的卡(适用于 Ubuntu 和 Windows)
注意:必须使用最新版本的 pip,才能安装 TensorFlow 2。
硬件要求
从 TensorFlow 1.6 开始,二进制文件使用 AVX 指令,这些指令可能无法在旧版 CPU 上运行。
阅读 GPU 支持指南,以在 Ubuntu 或 Windows 上设置支持 CUDA® 的 GPU 卡。

  1. 在系统上安装 Python 开发环境
    检查是否已配置 Python 环境:

需要使用 Python 3.6-3.9 和 pip 19.0 及更高版本

python3 --version
pip3 --version
如果已安装这些软件包,请跳至下一步。
否则,请安装 Python、pip 软件包管理器和 venv:

Ubuntu
macOS
Windows
其他

sudo apt update
sudo apt install python3-dev python3-pip python3-venv
注意:升级系统 pip 可能会导致问题。
如果不是在虚拟环境中,请针对下面的命令使用 python3 -m pip。这样可以确保您升级并使用 Python pip,而不是系统 pip。
2.创建虚拟环境(推荐)
Python 虚拟环境用于将软件包安装与系统隔离开来。

Ubuntu/macOS
Windows
Conda
创建一个新的虚拟环境,方法是选择 Python 解释器并创建一个 ./venv 目录来存放它:

python3 -m venv --system-site-packages ./venv
使用特定于 shell 的命令激活该虚拟环境:

source ./venv/bin/activate # sh, bash, or zsh

. ./venv/bin/activate.fish # fish

source ./venv/bin/activate.csh # csh or tcsh
当虚拟环境处于有效状态时,shell 提示符带有 (venv) 前缀。

在不影响主机系统设置的情况下,在虚拟环境中安装软件包。首先升级 pip:

pip install --upgrade pip

pip list # show packages installed within the virtual environment
之后退出虚拟环境:

deactivate # don’t exit until you’re done using TensorFlow
3.安装 TensorFlow pip 软件包
请从 PyPI 中选择以下某个 TensorFlow 软件包进行安装:

tensorflow:支持 CPU 和 GPU 的最新稳定版(适用于 Ubuntu 和 Windows)。
tf-nightly:预览 build(不稳定)。Ubuntu 和 Windows 均包含 GPU 支持。
tensorflow==1.15:TensorFlow 1.x 的最终版本。
系统会自动安装软件包依赖项。这些依赖项就列在 setup.py 文件的 REQUIRED_PACKAGES 下。
虚拟环境安装
系统安装

pip install --upgrade tensorflow
验证安装效果:

python -c “import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))”
成功:如果系统返回了张量,则意味着您已成功安装 TensorFlow。请查看教程开始使用。
软件包位置
部分安装方式需要您提供 TensorFlow Python 软件包的网址。您需要根据 Python 版本指定网址。

版本 网址
Linux
Python 3.6(支持 GPU) https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.6.0-cp36-cp36m-manylinux2010_x86_64.whl
Python 3.6(仅支持 CPU) https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.6.0-cp36-cp36m-manylinux2010_x86_64.whl
Python 3.7(支持 GPU) https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.6.0-cp37-cp37m-manylinux2010_x86_64.whl
Python 3.7(仅支持 CPU) https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.6.0-cp37-cp37m-manylinux2010_x86_64.whl
Python 3.8(支持 GPU) https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.6.0-cp38-cp38-manylinux2010_x86_64.whl
Python 3.8(仅支持 CPU) https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.6.0-cp38-cp38-manylinux2010_x86_64.whl
Python 3.9(支持 GPU) https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.6.0-cp39-cp39-manylinux2010_x86_64.whl
Python 3.9(仅支持 CPU) https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.6.0-cp39-cp39-manylinux2010_x86_64.whl
macOS(仅支持 CPU)
Python 3.6 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.6.0-cp36-cp36m-macosx_10_11_x86_64.whl
Python 3.7 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.6.0-cp37-cp37m-macosx_10_11_x86_64.whl
Python 3.8 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.6.0-cp38-cp38-macosx_10_11_x86_64.whl
Python 3.9 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.6.0-cp39-cp39-macosx_10_11_x86_64.whl
Windows
Python 3.6(支持 GPU) https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.6.0-cp36-cp36m-win_amd64.whl
Python 3.6(仅支持 CPU) https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.6.0-cp36-cp36m-win_amd64.whl
Python 3.7(支持 GPU) https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.6.0-cp37-cp37m-win_amd64.whl
Python 3.7(仅支持 CPU) https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.6.0-cp37-cp37m-win_amd64.whl
Python 3.8(支持 GPU) https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.6.0-cp38-cp38-win_amd64.whl
Python 3.8(仅支持 CPU) https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.6.0-cp38-cp38-win_amd64.whl
Python 3.9(支持 GPU) https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.6.0-cp39-cp39-win_amd64.whl
Python 3.9(仅支持 CPU) https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.6.0-cp39-cp39-win_amd64.whl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

百世修行

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值