Windows
1. Anaconda3 Setup
Download and run the Anaconda3 installer (e.g., Anaconda3-2019.03 for Python 3.7). During installation, you can allow it to register Python in the system PATH or rely on the Anaconda Prompt later.
2. Verifying the Installation
Open a terminal (cmd or Anaconda Prompt) and check the conda version:
conda --version
List existing environments:
conda info --envs
3. Creating a TensorFlow Environment
Create a dedicated conda environment with Python 3.7:
conda create --name tf_env python=3.7
Activtae it:
conda activate tf_env
To speed up pip downloads, you can configure a mirror in C:\Users\<username>\pip\pip.ini:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
Install TensorFlow using pip:
pip install --upgrade tensorflow
4. Smoke Test
While the environment is active, launch Python and run:
import tensorflow as tf
msg = tf.constant('Hello, TensorFlow!')
with tf.compat.v1.Session() as sess:
print(sess.run(msg))
If you see b'Hello, TensorFlow!', the installation is correct.
Linux
1. Choosing the Right Installer
Check the system architecture and kernel version:
uname -a
Download the matching Anaconda3 Linux installer (e.g., Anaconda3-2019.03-Linux-x86_64.sh).
2. Installing Anaconda3
Run the installer script:
bash Anaconda3-2019.03-Linux-x86_64.sh
Accept the license and choose a custom installation path, for instance /home/user/anaconda3. When asked whether to initialize conda, answer yes.
To keep the system Python (e.g., Python 2.7 used by Hadoop) unchanged, edit ~/.bashrc and comment out the entire conda initialize block. Add the following line instead:
export PATH="/usr/bin:$PATH:/home/user/anaconda3/bin:/home/user/anaconda3/condabin"
Reload the configuration with source ~/.bashrc. Confirm the system Python still points to version 2:
python --version
3. Setting Up TensorFlow
Create a new environment:
conda create -n tf_env python=3.7
Activate it:
source activate tf_env
Install TensorFlow via conda (this resolves dependencies more reliably on some Linux distributions):
conda install tensorflow -n tf_env
4. Validation
Start Python in the activated environment and test:
import tensorflow as tf
msg = tf.constant('Hello, TensorFlow!')
with tf.compat.v1.Session() as sess:
print(sess.run(msg))
Expected output: b'Hello, TensorFlow!'.