1、下载安装Anaconda
Anaconda创建环境:
conda create -n py36 python=3.6 //下面是创建python=3.6版本的环境,取名叫py36
删除环境
conda remove -n py36 --all
激活环境
source activate py36 //下面这个py36是个环境名
退出环境
source deactivate
2、创建名为tensorflow运行环境
conda create -n tensorflow pip python=2.7 # or python=3.3, etc.
3、激活当前环境
source activate tensorflow
4、安装Tensorflow
pip install --ignore-installed --upgrade TF_PYTHON_URL
TF_PYTHON_URL为Tensorflow软件包网站,可在https://www.tensorflow.org/install/pip查看,这是1.12.0的网址
版 | 网址 |
---|---|
Linux的 | |
Python 2.7仅限CPU | https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp27-none-linux_x86_64.whl |
Python 2.7 GPU支持 | https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp27-none-linux_x86_64.whl |
Python 3.4仅限CPU | https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp34-cp34m-linux_x86_64.whl |
Python 3.4 GPU支持 | https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp34-cp34m-linux_x86_64.whl |
Python 3.5仅限CPU | https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl |
Python 3.5 GPU支持 | https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp35-cp35m-linux_x86_64.whl |
Python 3.6仅限CPU | https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl |
Python 3.6 GPU支持 | https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp36-cp36m-linux_x86_64.whl |
macOS(仅限CPU) | |
Python 2.7 | https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py2-none-any.whl |
Python 3.4,3.5,3.6 | https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl |
视窗 | |
Python 3.5仅限CPU | https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp35-cp35m-win_amd64.whl |
Python 3.5 GPU支持 | https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.12.0-cp35-cp35m-win_amd64.whl |
Python 3.6仅限CPU | https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp36-cp36m-win_amd64.whl |
Python 3.6 GPU支持 | https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl |
出现错误:Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/wl/pd1h6scx22bf7b_f1st_w82h0000gn/T/pip-install-kzk5nbp5/gast/...
解决方法:这意味着您的setuptools已过期。
您可以通过以下方式解决此问题pip install --upgrade setuptools
5、验证运行
调用python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))