TensorFlow installation of an ANA Conda-based environment

Source: Internet
Author: User
Tags constant continuum analytics cuda toolkit

TensorFlow installation is divided into two cases, one is CPU only, and the other is the use of the GPU, which also installs Cuda and CUDNN, the situation is relatively complex. The above two categories recommend using Anaconda as the Python environment, and the basic version of Python is version 3.5. This article is to give the Conda environment configuration installation of TensorFlow, you can not install anaconda outside the environment of Python independently. Pre-installation conditions

Install Python and Environment Configuration Reference blog post:
Python installation http://blog.csdn.net/cs_leebo/article/details/64442156 in Ubuntu environment
After installing Python, you will also need to install PYTHON-PIP and Python-dev
Input command: $ sudo apt-get install Python-pip Python-dev

Pip can be understood as a more advanced software installer, the installation of TensorFlow to use. Dev is an additional class library, which is also required for tensorflow installation and operation.

For Python3. X-Series execution environment. You need to install PYHON3-PIP
$pip –version View the PIP version
Way One:
sudo aptitude install Python3-pip
Way two:
Installing sudo apt-get install Python3-pip
Uninstalling sudo apt-get remove Python3-pip

For PYTHON-PIP upgrade issues, follow the relevant prompts, normal can be maintained by default. 1, installation Anaconda

Anaconda is a scientific computing release for Python. The default contains Python3. X-Series environment. The package manager used by Anaconda is "Conda" and Conda environments is independent of other Python projects. The TensorFlow installed in the ANACONDA environment environment will not overwrite the TensorFlow installed in the previous Python environment. However, you should uninstall the TensorFlow installed outside

Anaconda Installation steps:
Install Anaconda.
Create a Conda environment.
Activate the Conda environment and install TensorFlow in it.
After the install, you'll activate the Conda environment each time, want to use TensorFlow.
Optionally install Ipython and other packages into the Conda environment.

Note: Before uninstalling the TensorFlow installed via PIP, if not installed, skip here.
If TensorFlow have been installed via PIP outside the Anaconda environment previously, then one should uninstall it if one Wants to use the TensorFlow installed within a Anaconda environment, because Anaconda searches system site-packages from . Local with higher priority. "' Bash
Python 2
Pip Uninstall TensorFlow
Python 3
PIP3 Uninstall TensorFlow

Tsinghua Software Source https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
After downloading, execute #bash anaconda3-4.3.0-linux-x86_64.sh
After executing the license document is displayed, press the Q key to skip, enter Yes to confirm. After installation, configure the environment variables under the ~/.BASHRC file:
Export path= "/home/leebo/anaconda3/bin: $PATH" Restart terminal configuration complete.

1.1 Conda Installation
Conda is an open source package management system and environment management system for installing multiple versions of packages and their dependencies and switching between them easily.
Common commands: Conda list lists the packages that are linked to the current Conda environment
Conda create creates a Conda environment with the name TF
Conda create-n Environment Name-c Mirror Source

1.2 Creating the Conda execution Environment
Create a Conda environment called TensorFlow:

Python 2.7
$ Conda create-n TensorFlow python=2.7

Python 3.4
$ Conda create-n TensorFlow python=3.4

Python 3.5
$ Conda create-n TensorFlow python=3.5

After the installation is complete, use the following command to activate \ Shutdown, Conda the execution environment.
To activate the environment, use:

SOURCE Activate TensorFlow
To deactivate the environment, use:
SOURCE Deactivate TensorFlow

After activating the Conda environment, you can install TENSORFOLW using either Conda or Pip two methods. 2, installation TensorFlow

2.1 Install TensorFlow using the Conda command
Using Conda refer to the following URLs
A community maintained Conda package was available from Conda-forge.
Https://github.com/conda-forge/tensorflow-feedstock

Only the CPU version of TensorFlow was available at the moment and can being installed in the Conda environment for Python 2 O R Python 3.

$ source Activate TensorFlow
(TensorFlow) $ # Your prompt should change linux/mac OS X, Python 2.7/3.4/3.5, CPU only:

(TensorFlow) $ conda install-c conda-forge tensorflow

2.2. Install TensorFlow using PIP command
If using PIP make sure to use the–ignore-installed flag to prevent errors about easy_install.
$ source Activate TensorFlow
(TensorFlow) $ # Your prompt should change

2.2.1, TensorFlow CPU version installation
Export TF_BINARY_URL=HTTPS://STORAGE.GOOGLEAPIS.COM/TENSORFLOW/LINUX/CPU/TENSORFLOW-1.0.0RC0-CP35-CP35M-LINUX_X86_64.WHL

Finally Install TensorFlow:
Python 2
(tensorflow) $$ pip Install–ignore-installed–upgrade $TF _binary_url

Python 3
(tensorflow) $$ pip3 install–ignore-installed–upgrade $TF _binary_url

Error message hint
1) TENSORFLOW-1.0.0RC0-CP35-CP35M-LINUX_X86_64.WHL is not a supported wheel on this platform.

You need to change the source address of the Tf_binary_url.
$ Export Tf_binary_url=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.0rc1-cp34-cp34m-linux _x86_64.whl

2) appears permissionerror: [Errno 13] Insufficient permissions:/usr/local/lib/python3.5/dist-packages/numpy-1.12.1.dist-info error message, execute the following installation command.
$pip Install Packagename–user

2.2.2, TensorFlow GPU version installation
For NVIDIA graphics cards, you need to install video driver, CUDA, CuDNN
Cuda is the SDK that Nvidia has introduced to compute using GPU resources, with the graphics driver integrated in Cuda.
Https://developer.nvidia.com/cuda-toolkit

Ubuntu/linux 64-bit, GPU enabled. Requires CUDA Toolkit 7.5 and CuDNN v4. For
Other versions the "Install from sources" below.
$ sudo pip3 install–upgrade https://sto 3, tensorflow after installation

With the Conda environment activated, you can now test your installation.
When you were done using TensorFlow, deactivate the environment.
(TensorFlow) $ Source Deactivate

$ # Your prompt should change back

To use TensorFlow later you'll have to activate the Conda environment again:
$ Source Activate TensorFlow
(tensorflow) # Your prompt should change.
Run Python programs that use TensorFlow.
...
When you were done using TensorFlow, deactivate the environment.
(tensorflow) # Your prompt should change. Run Python programs that use TensorFlow. ... When you were done using TensorFlow, deactivate the environment. (TensorFlow) Source Deactivate 4. Example

(tensorflow) android@local:~$ python
Python 3.4.5 | Continuum Analytics, inc.| (Default, Jul 2 2016, 17:47:47)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on Linux
Type "Help", "copyright", "credits" or "license" for more information.

Import TensorFlow as TF
Hello = tf.constant (' hello,tensorflow! ')
Sess = tf. Session ()
Print (Sess.run (hello))
B ' hello,tensorflow! '
A=tf.constant (10)
B=tf.constant (32)
Print (Sess.run (a+b)) 5, other kit installation,

Ipython Tool Kit
IPython is a python interactive shell that works much better than the default Python shell, supports variable auto-completion, auto-indent, supports bash shell commands, and has many useful functions and functions built into it.
IPython is based on BSD open source.
IPython provides a rich architecture for interactive computing, including:
Powerful, interactive shell
Jupyter kernel
Interactive Data visualization Tools
Flexible, embeddable interpreter
Easy-to-use, high-performance parallel Computing tool [1]
Installation
Under Ubuntu as long as sudo apt-get install Ipython installed, through Ipython boot.

To use TensorFlow with IPython it is necessary to install IPython into the TensorFlow environment:
Sourceactivatetensorflow (tensorflow) source activate TensorFlow (tensorflow) Conda install Ipython

Similarly, other Python packages like pandas could need to get installed into the TensorFlow environment before they can be Used together with TensorFlow. 6. Common Problems and Errors

6.1 Installation Guide website
Https://www.tensorflow.org/versions/master/get_started/os_setup.html#anaconda-installation

6.2 After installation, run the instance prompt Modulenotfounderror:no module named ' TensorFlow '
Import TensorFlow as TF
Traceback (most recent):
File "", Line 1, in
Modulenotfounderror:no module named ' TensorFlow '
Workaround: Do not install a version that is too new

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.