tensorflow assembled and tested under mac

Install the Anaconda ( click to enter the official website ). Python because it integrates many third-party libraries, and can easily manage different versions of Python, switch between different versions of Python. And Anaconda is a scientific computing environment, after the installation of Anaconda on the computer, in addition to the equivalent of the Python installed, also installed some commonly used libraries.

Installed Anaconda

I installed the Python 2.7 version of Anaconda, after installed Anaconda, has been installed the Python library and a number of commonly used. In addition, the automatic installation of the Spyder.

Spyder is a simple Python integrated development environment, and other Python development environment compared to its biggest advantage is that mimic the functions of "working space" MATLAB can be easily observed and modify the array.

In the input terminal Spyder you can open it, as shown below:

Write pictures described here
Write pictures described here

But I prefer to use as a development environment Pycharm

Third, the establishment, activation, installation Tensorflow

Open the terminal, enter at:

conda create -n tensorflow python=2.7

Establish Tensorflow operating environment

Then, etc. After finished, then execute:

source activate tensorflow

At this point activates the operating environment.

And then run pip install tensorflowfor Tensorflow installation.

If you experience very slow and the installation failed, this time Hou consider using domestic mirror address

Commonly used are the following:

Ali cloud
http://mirrors.aliyun.com/pypi/simple/

China University of Science and Technology
https://pypi.mirrors.ustc.edu.cn/simple/

watercress (douban)
http://pypi.douban.com/simple /

Tsinghua University
https://pypi.tuna.tsinghua.edu.cn/simple/ (this address speed test well)

University of China Science and technology
http://pypi.mirrors.ustc.edu.cn/simple/

Of course, the installation command need to add parameters    

pip install tensorflow -i  https://pypi.tuna.tsinghua.edu.cn/simple/

 

Hello Tensorflow then execute the following code tests whether the installation was successful Tensorflow

import tensorflow as tf
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
a=tf.constant(2)
b=tf.constant(3)
with tf.compat.v1.Session() as sess:
print("a:%i" % sess.run(a),"b:%i" % sess.run(b))
print("Addition with constants: %i" % sess.run(a+b))
print("Multiplication with constant:%i" % sess.run(a*b))

Note that this oh tf.compat.v1.Session (), because I was a big change in version 1.x and 2.1 versions of.

 

 result

 

 


 

Guess you like

Origin www.cnblogs.com/schyzhkj/p/12633254.html