[PYTHON] Build a machine learning environment using PyCharm on Ubuntu environment (TensorFlow will also be introduced!)

Machine learning is popular these days, but I felt that it was difficult to build an environment in many situations, so I would like to make an article as a memorandum and provide one piece of information.

environment Ubuntu 16.04.1 LTS on Windows 10 (using VirtualBox)

Purpose of the article

This article is about enabling machine learning and deep learning with PyCharm on the newly installed guest operating system Ubuntu. Specifically, make it possible to use TensorFlow, NumPy, etc.

procedure

  1. Install Anaconda3 (this will prepare the basic Python environment)
  2. Building a Python 3.5 environment
  3. Install and configure PyCharm
  4. Install TensorFlow
  5. Confirmation

Installation of Anaconda3

From here, check the OS bit, Python version, etc., and install the appropriate one. I downloaded the Python 3.6 installer for Linux. For more information [here [4]](http://pythondatascience.plavox.info/python%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88 See% E3% 83% BC% E3% 83% AB / anaconda-ubuntu-linux /). anaconda_install.PNG

After the installation is complete, the sh file will be created under the ~ / Downloads directory. Type the following command. Refer to the site of [4] and proceed (if you are asked yes / no, yes otherwise, you can press Enter).

bash ~/Downloads/Anaconda3-4.3.0-Linux-x86_64.sh


echo 'export PATH=/home/user/anaconda3/bin:$PATH' >> ~/.bashrc
source ~/.bashrc```

 * (The above version of Anaconda seems to be installed at the moment. Please check the version before executing the command)
 It is OK if you can display the version of conda with the following command.


#### **`conda -V #conda 4.3.8`**

Also check the Python version.

python --version #Python 3.6.0 :: Anaconda 4.3.0 (64-bit)



 The version of python seems to be 3.6.0.
 It should be noted here that TensorFlow seems to support up to 3.5 for Python 3 series at the moment. Therefore, we are going to build an environment for TensorFlow with anaconda.


## Create an environment for Python 3.5
 Execute the following command. Create a Python 3.5 version environment with the name tf.


#### **`conda create -n tf python=3.5 anaconda`**
```5 anaconda


 Now you can enter the python3.5 environment with source arctivate tf. Let's execute the command.
 (Source deactivate if deactivated)

source arctivate tf

## Install TensorFlow
 Install TensorFlow. Execute the following command.

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp35-cp35m-linux_x86_64.whl pip install --upgrade $TF_BINARY_URL


## Install PyCharm
 Download PyCharm from [here](http://www.jetbrains.com/pycharm/download/#section=linux). This time we will use the community edition.

 Go to the directory where the downloaded file is located. If you don't know the directory, in Firefox you can see the download list by clicking the down arrow button in the upper right corner. Click the folder button to the right of the file you want to see the directory to jump to the directory where the file is located.

 In the directory, this time unzip the "pycharm-community-2016.3.2.tar.gz" file. You can use the command, but this time, right-click the file and select "Extract to" to extract it while specifying the extraction destination. The decompression destination is the user's home directory.

 PyCharm is executed by the following command.

bash pycharm-community-2016.3.2/bin/pycharm.sh


 Create a new project with Create New Project.
 ![Pycharm_newProject.PNG](https://qiita-image-store.s3.amazonaws.com/0/120532/66b88ba4-c5db-4f9d-68cc-ecc4966aae26.png)

 Then specify Interpreter. In my environment, I specified ~ / anaconda3 / envs / tf / bin / python. If you don't know which one to specify, just keep the defaults and proceed. The project will be created (it may take some time).
 ![pycharm_interpreter.PNG](https://qiita-image-store.s3.amazonaws.com/0/120532/2b8eb9a1-1113-3323-4c2e-961a0548ef41.png)

 To select Interpreter, select File-> settings-> Project: Project Name-> Project Interpreter on the toolbar.
 * It seems that settings may be referred to as preference.

 ![asdf.PNG](https://qiita-image-store.s3.amazonaws.com/0/120532/e5dc4d48-0d35-115c-d580-2173fc4fae7a.png)

 You can select Interpreter from the pull-down menu. Also, you can see what kind of package is included, so select the one that contains the necessary items. This time, I judged whether tensorflow, matplotlib, and numpy are included.

 ![sdf.PNG](https://qiita-image-store.s3.amazonaws.com/0/120532/a6a3f2c1-a11b-72f9-28d0-86349d6dd075.png)
 * You can check the package and version

## Verification
 Now, let's check if TensorFlow etc. actually works properly.
 Create a Python file. This time it was main.py.

 ![sa.PNG](https://qiita-image-store.s3.amazonaws.com/0/120532/cc053ec2-2e61-04aa-4a64-3890956fe321.png)

 Type in the following Python code and execute it (you can execute it with ctrl + shift + F10). I referred to [here](http://dev.classmethod.jp/machine-learning/tensorflow-hello-world/) (However, since it was written in Python2 series, it has been rewritten to Python3 series).


#### **`main.py`**
```python

import tensorflow as tf
import multiprocessing as mp

core_num = mp.cpu_count()
config = tf.ConfigProto(
    inter_op_parallelism_threads=core_num,
    intra_op_parallelism_threads=core_num)
sess = tf.Session(config=config)

hello = tf.constant('hello, tensorflow!')
print(sess.run(hello))

a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))

If you get the following result, you are successful. result.PNG

また、MatplotlibとNumPyについても見てます。コードを上書きしてください。こちらを参考にしました。

main.py


import numpy as np
import matplotlib.pyplot as plt

X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
C, S = np.cos(X), np.sin(X)

plt.plot(X, C)
plt.plot(X, S)

plt.show()

If it becomes as follows, it is successful. matresult.PNG

That is all. Thank you for your hard work! Again, if you find something wrong or something you need to improve, please comment. happy. We are also grateful to those who share useful information, including the linked articles. Finally, have a fun machine learning life!

Recommended Posts

Build a machine learning environment using PyCharm on Ubuntu environment (TensorFlow will also be introduced!)
Build a machine learning environment
Build a machine learning Python environment on Mac OS
Build a machine learning environment natively on Windows 10 (x64)
Build an environment for machine learning using Python on MacOSX
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
A story about simple machine learning using TensorFlow
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Build a Kubernetes environment for development on Ubuntu
Build a Python machine learning environment with a container
Build a Django development environment using pyenv-virtualenv on Mac
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Build a Python environment on your Mac using pyenv
Build a machine learning application development environment with Python
Build a Python development environment using pyenv on MacOS
Memo for building a machine learning environment using Python
How to build a new python virtual environment on Ubuntu
Launching a machine learning environment using Google Compute Engine (GCE)
Build a PyData environment for a machine learning study session (January 2017)
Until building a Python development environment using pyenv on Ubuntu 20.04
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
Build a Chainer environment using CUDA and cuDNN on a p2 instance
Build a go environment using Docker
Building a Python environment on Ubuntu
Build a Python environment on your Mac with Anaconda and PyCharm
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
Using a serial console on Ubuntu 20.04
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Build a python3 environment on CentOS7
How to quickly create a machine learning environment using Jupyter Notebook on macOS Sierra with anaconda
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Until the Deep Learning environment (TensorFlow) using GPU is prepared for Ubuntu 14.04
Build a "Deep learning from scratch" learning environment on Cloud9 (jupyter miniconda python3)
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
Build a Tensorflow environment with Raspberry Pi [2020]
I built a TensorFlow environment on windows10
Build a Python + OpenCV environment on Cloud9
Creating a development environment for machine learning
Build AI / machine learning environment with Python
From nothing on Ubuntu 18.04 to setting up a Deep Learning environment in Tensor
Build a TensorFlow development environment on Amazon EC2 with command copy and paste
A addictive story when using tensorflow on Android
Build a LAMP environment on your local Docker
Build a WardPress environment on AWS with pulumi
Build python environment with pyenv on EC2 (ubuntu)
Simply build a Python 3 execution environment on Windows
[Latest] How to build Java environment on Ubuntu
Build a Django environment on Raspberry Pi (MySQL)
Build a python environment with ansible on centos6
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on your Mac
[Venv] Create a python virtual environment on Ubuntu
Try using tensorflow ① Build python environment and introduce tensorflow
Notes for using TensorFlow on Bash on Ubuntu on Windows
How to build Java environment on Ubuntu (Linux)
Install the machine learning library TensorFlow on fedora23
Build a Python development environment on Raspberry Pi
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS