【MacOS】使用pip安装Tensorflow

System requirements

  • macOS 10.12.6 (Sierra) or later (64-bit) (no GPU support)

1. Install the Python development environment on your system

查看python是否符合条件:Python 3.4, 3.5, or 3.6

terminal输入:

python3 --version
pip3 --version
virtualenv --version

如果你都装过了,跳到第二步,如果没装,复制下面代码。

  • 注意这里使用Homebrew。请先安装Homebrew,复制到terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 然后复制以下内容到terminal进行安装:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
brew update
brew install python  # Python 3
sudo pip3 install -U virtualenv  # system-wide install

2. 推荐建立virtual environments

Python virtual environments are used to isolate package installation from the system.
这里放了两个: 一个是Mac,一个是Conda。

  • Create a new virtual environment by choosing a Python interpreter and making a ./venv directory to hold it:
virtualenv --system-site-packages -p python3 ./venv #mac用这个
conda create -n venv pip python=3.6  # select python version #conda用这个
  • Activate the virtual environment using a shell-specific command:
source ./venv/bin/activate  # sh, bash, ksh, or zsh
source activate venv   #conda的
  • When virtualenv is active, your shell prompt is prefixed with (venv).
  • Install packages within a virtual environment without affecting the host system setup.
pip install --upgrade pip
pip list  # show packages installed within the virtual environment
#mac的
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.13.1-py3-none-any.whl
#Conda的 #macOS (CPU-only) Python 3.4, 3.5, 3.6	
  • And to exit virtualenv later:
deactivate  # don't exit until you're done using TensorFlow
conda deactivate  #conda的

3. 安装TensorFlow pip package

Choose one of the following TensorFlow packages to install from PyPI:

其实就这一句是核心

pip install tensorflow

tensorflow —Latest stable release for CPU-only (recommended for beginners)
tensorflow-gpu—Latest stable release with GPU support (Ubuntu and Windows)
tf-nightly —Preview nightly build for CPU-only (unstable)
tf-nightly-gpu —Preview nightly build with GPU support (unstable, Ubuntu and Windows)
tensorflow==2.0.0-alpha0 —Preview TF 2.0 Alpha build for CPU-only (unstable)
tensorflow-gpu==2.0.0-alpha0 —Preview TF 2.0 Alpha build with GPU support (unstable, Ubuntu and Windows)

  • Virtualenv install:
pip install --upgrade tensorflow
  • Verify the install:
python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

Success: TensorFlow is now installed. Read the tutorials to get started.

用anaconda的jupyter book跑了一下,还行,能用:

conda

官网:
https://www.tensorflow.org/install/pip#package-location
https://pypi.org/project/tensorflow/
https://anaconda.org/conda-forge/tensorflow

猜你喜欢

转载自blog.csdn.net/weixin_42317507/article/details/89071751
今日推荐