When I tried to use python on my previous computer, I had a lot of trouble building the environment.
As a result of searching various things on my own, I found that it was terrible, such as building by mixing various methods and getting a lot of warning sentences. .. .. ..
For those who read this article, I would like to introduce you so that you can easily build the environment of python and use tensorflow.
-Enable Python with Anaconda. -Create an execution environment with conda. -Install tensorflow in the execution environment, write sample code to see if it can be used, and execute it.
I would like to proceed with this kind of content.
I checked it on the tensorflow homepage.
An open-source software library for Machine Intelligence ~~ Open source software for artificial intelligence ~~
... apparently ...
Official site: Tensorflow
This time, we will use anaconda, which will be introduced later, to make various settings, so you do not have to install it at this time.
MAC OS:Sierra 10.12.5 python:3.5.2(Anaconda 4.2.0) tensorflow:1.1
By the way, according to the official Tensorflow document at the end of June 2017,
Prerequisite: Python
In order to install TensorFlow, your system must contain one of the following Python versions: ~~ Before installing tensorflow, your system must include the python version below ~~
Python 2.7 Python 3.3+
That's why you need 3.3 or higher.
If you are interested, please enter the following command in ** Terminal ** and check if the version is correct.
It is natural to know the terminal when studying other languages to some extent, and there is no explanation as to whether the environment construction in Qiita's article is done with python.
So this time I will also introduce how to open the terminal
Please check the following page as it is introduced in another article.
Now, open a terminal and enter the following command.
Your macbook-Pro:~Your username$ python
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default,date)
〜〜〜〜
〜〜〜〜
>>>
** * If you want to exit the python interpreter, enter ctr + d. ** **
By the way, when I checked, my python was 3.5.
You can also check with the following command.
Your macbook-Pro:~Your username$python --version
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
Python2 series is installed on mac by default.
If you do not have the Python 3 series and conda introduced this time installed, go to the bottom and install Anaconda.
According to the homepage of Anaconda
Anaconda is the leading open data science platform powered by Python. The open source version of Anaconda is a high performance distribution of Python and R and includes over 100 of the most popular Python, R and Scala packages for data science. ~~ It's a python data science platform. ~~ ~~ There are a lot of packages. ~~
... apparently ...
According to Anaconda's Wikipedia
Anaconda is an operating system installer used by CentOS and Fedora. It is implemented in Python and C. PyGTK is used for the GUI front end, and Python-newt is used for the text mode front end.
In other words, if it is true, it is a package that contains all the libraries that you have to install one by one.
It also contains the conda required to create a python3 system or virtual environment.
If you install it, anaconda will do it for you, so I will omit it this time except for the outline.
Official: DOWNLOAD ANACONDA NOW
As I mentioned earlier, let's check the python version after installation.
If it is still python2 system even if you check it with the interpreter, it is possible that the PATH does not pass, so enter the following command.
Your MacBook-Pro: ~ your username $ export PATH = / Users / your username / anaconda / bin: $ PATH
Please specify the user name of the mac you are using in the "Your user name" part.
Let's start the python interpreter in the terminal again.
conda is a package management system and environment management system made primarily for Python.
It is not released as a standalone product, but is included in Anaconda, Anaconda server, and Miniconda.
Recently, it is popular because various packages can be easily installed to build a numerical calculation environment for Python.
It's conda, not Neda.
By introducing conda, it is possible to create various virtual environments.
Now, enter the following command to open the virtual environment of conda.
conda create -n environment name you want to create python = your python version
This time, we will create a virtual environment named tensorflow using python3.5, so the command will be as follows.
$ conda create -n tensorflow python=3.5
After entering the command and completing the installation, an execution environment named "tensorflow" that can use tensorflow will be created.
We don't have tensorflow at this point, so we don't have to create it with this name.
It is also easy to understand if you set the name by version etc.
1000ch: Building a Python environment on Mac using pyenv
You can move (activate) the execution environment created by conda by entering the following command.
$ source activate
The environment name created earlier`
I created a virtual environment with the name tensorflow, so the command to enter is as follows.
$ source activate tensorflow
If successful, the name of tensorflow will appear on the left side as shown below.
(tensorflow) Your MacBook-Pro: ~ Your username $
Enter the following command to return to the original hierarchy from the execution environment (deactivate).
$ source deativate tensorflow
The next step is to install tensorflow.
Install tensorflow with the following command.
$ conda install -c conda-forge tensorflow
mkl: 2017.0.1-0
mock: 2.0.0-py35_0 conda-forge
numpy: 1.13.0-py35_0
pbr: 3.1.1-py35_0 conda-forge
protobuf: 3.3.0-py35_2 conda-forge
six: 1.10.0-py35_1 conda-forge
tensorflow: 1.1.0-py35_0 conda-forge
werkzeug: 0.11.10-py35_0 conda-forge
Proceed ([y]/n)?
I was asked to enter Yes or No, so I chose yes.
Open a terminal and check if the tensorflow you just installed is installed.
///① Start python in the execution environment
(tensorflow)Your macbook-Pro:~Your username$ python
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default,Today's date
・ ・ ・(Various come out)
・ ・ ・
///② Import tensorflow.(If you can import it, you have installed it.)
>>>import tensorflow as tf
///③ Again as shown below>>>If appears, you can install it.
>>>
>>>import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'tensorflow'
It may be possible to solve it, so if you can not import it, please comment with copy and paste.
python
>>>import tensorflow as tf
>>>hello = tf.constant("Hello Tensorflow!")
>>>sess = tf.Session() //Note that Session has an uppercase letter
>>>print(sess.run(hello)) //Run the hello you just created in session
b'Hello Tensorflow!'
↑ If it is output like this, it is proof that you can use tensorflow! !! !!
1: Import tensorflow in the first line and set it to be called with the name tf. 2: Create a constant that outputs "Hello Tensorflow!" With the name hello 3: Create sess using Session to execute 4: Execute hello using sess and output with print.
The TensorFlow graph is a description of the calculation. Whatever calculation you do, you need to run the graph inside a Session. Session provides a way to place graph ops on devices such as CPUs and GPUs and execute them.
Source: Run TensorFlow from the command line
I don't know the detailed movement, but it means that you have to use session.
I would appreciate it if you could comment if there are any mistakes in the article (^^)
Next time, I will write about MNIST For ML Bigginers in the tensorflow tutorial!
Thank you very much!
Recommended Posts