Build a machine learning application development environment with Python

I will explain the procedure to introduce the development environment of machine learning application with Python, specifically Numpy / Scipy / scikit-learn. The environment is assumed to be Python3 based.

Miniconda base (recommended)

Since many machine learning packages are troublesome to compile, it is recommended to build an environment with conda (Miniconda) where you can install compiled binaries. To do.

First, we will build a basic environment such as Python itself (assuming Python 3), pip, which is a package management tool, and virtualenv, which creates a virtual environment.

Mac/Linux Use pyenv to install it separately from the default Python.

# confirm installation
pyenv --version

# show python environments list
pyenv install -l

# install newest miniconda
pyenv install miniconda3-x.x.x

# refresh pyenv
pyenv rehash

# activate installed python environment globally
pyenv global miniconda3-x.x.x

If you want to switch the Python used in each project, you can set it with pyenv local x.x.x. You will need pyenv rehash after installing the new Python environment with pyenv (see here). Please note that it is easy to forget.

After installing Miniconda, use conda to build the virtual environment ml_env for machine learning (whatever the name is).

conda create -n ml_env numpy scipy scikit-learn matplotlib cython jupyter

Once created, let's enable this virtual environment for machine learning.

source activate ml_env ... should be fine, but when using pyenv, it seems that ʻactivate of pyenv and ʻactivate of conda are batting, and there are cases where the shell falls. As a workaround, specify the activate of conda properly with the full path. Check the location of the virtual environment created by conda with conda info -e, and start ʻactivate in bin` there.

conda info -e
# conda environments:
#
ml_env                   /usr/local/pyenv/versions/miniconda3-3.4.2/envs/ml_env
root                  *  /usr/local/pyenv/versions/miniconda3-3.4.2

source /usr/local/pyenv/versions/miniconda3-3.4.2/envs/ml_env/bin/activate ml_env

However, this is troublesome. pyenv local seems to be able to specify the environment created by Miniconda, so I think pyenv local miniconda 3-3.4.2 / envs / ml_env is easier.

Windows

After installing Miniconda, use conda from the command prompt to build the virtual environment ml_env for machine learning (whatever the name is).

conda create -n ml_env numpy scipy scikit-learn matplotlib cython jupyter

Once created, let's enable this virtual environment for machine learning.

activate ml_env

virtualenv-based (for those familiar with Python)

If you don't use Miniconda (if you use virtualenv), you'll need to compile Numpy / Scipy. The procedure for building that environment is explained below. It is assumed that Python, pip, and virtualenv are already included.

Mac You need to install gcc / gfortran, so install Xcode and Xcode CommandLine Tools.

The Xcode command line tool can be installed with the following command after installing Xcode.

xcode-select --install

Since gfortran is required to install scipy, I will install it as well.

GFortranBinariesMacOS

The environment should be ready now ... so let's check the operation. Create an appropriate folder and create a virtual environment for machine learning there. Use requirements.txt in Gist here.

mkdir ml_env_test
cd ml_env_test

#Create a virtual environment
virtualenv venv

#Enable virtual environment
source venv/bin/activate

#Requirements from RAW on GitHub.Get txt(You can copy it normally to create a text file)
curl https://gist.githubusercontent.com/icoxfog417/420ac8eb3fad524ee2d6/raw/ac4122eb7b53b40274d2e7ced224abaa28a383c7/requirements.txt > requirements.txt

#Install dependent libraries
pip install -r requirements.txt

Installation of scipy is quite slow and consumes memory, so if you are running Chrome or something, you will get a Memory Error. Let's pray for the compilation and wait quietly.

When pip install is completed, the operation check is completed.

Linux(Ubuntu)

I think it's okay if you apt-get the following (Ubuntu 14.04).

build-essential
gfortran
libgfortran3
python-dev(python3-dev)
libblas-dev
libatlas-base-dev
cython

The command to build a virtual environment is the same as for Mac, so refer to the above.

Windows

Compiling on Windows is a daunting task, so download the compiled binary from here and install it.

Unofficial Windows Binaries for Python Extension Packages

Use the .whl file you can get here and install withpip install <file_path>. The required libraries are as shown in requirements.txt here.

mkdir ml_env_test
cd ml_env_test

#Create a virtual environment
virtualenv venv

#Enable virtual environment
venv\Scripts\activate

# (From the above site.Drop the whl file)

# .Install whl files(Below is an example of numpy)
pip install numpy‑1.9.2+mkl‑cp34‑none‑win32.whl

If you want to compile by yourself, you need to install Visual Studio, MinGW / Cygwin, etc., so it's a big way. I think it's best to stop unless there is something special.

Please refer to here for details.

Use automatic construction technology

koudaiii prepared Docker and shiraco prepared Ansible, so you can put it in.

koudaiii/ml-handson shiraco/ansible_ipython_machineleaning_bootstrap_conda

Operation check

After successfully enabling the virtual environment (plus pip install for virtualenv), try launching jupyter notebook. We have prepared a repository that explains scikit-learn, so please check if you can see it.

git clone https://github.com/icoxfog417/scikit-learn-notebook.git
cd scikit-learn-notebook
jupyter notebook

Other reference materials

Recommended Posts

Build a machine learning application development environment with Python
Build a Python machine learning environment with a container
Build AI / machine learning environment with Python
Build a machine learning environment
[Python] Build a Django development environment with Docker
Build a machine learning Python environment on Mac OS
Build a python machine learning study environment on macOS sierra
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
How to build a python2.7 series development environment with Vagrant
Easily build a development environment with Laragon
Build a python virtual environment with pyenv
Build a modern Python environment with Neovim
Creating a development environment for machine learning
Building a Windows 7 environment for getting started with machine learning with Python
Build a C language development environment with a container
Build Python development environment with Visual Studio Code
Build a python environment with ansible on centos6
Create a python3 build environment with Sublime Text3
Build a Python development environment on your Mac
Build a Django development environment with Doker Toolbox
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Build a Python development environment on Raspberry Pi
Build a python execution environment with VS Code
Get a quick Python development environment with Poetry
Machine learning with Python! Preparation
Build python3 environment with ubuntu 16.04
Build python environment with direnv
[ev3dev × Python] Build ev3dev development environment
Build a Python environment offline
Beginning with Python machine learning
I tried to build a Mac Python development environment with pythonz + direnv
Learning history to participate in team application development with Python ~ Build Docker / Django / Nginx / MariaDB environment ~
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build an interactive environment for machine learning in Python
Run a machine learning pipeline with Cloud Dataflow (Python)
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a python environment for each directory with pyenv-virtualenv
Create a python development environment with vagrant + ansible + fabric
Build a GVim-based Python development environment on Windows 10 (1) Installation
Build a Python development environment on Mac OS X
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a Python development environment using pyenv on MacOS
Build a development environment with Poetry Django Docker Pycharm
Memo for building a machine learning environment using Python
Set up a Python development environment with Sublime Text 2
Create a machine learning environment from scratch with Winsows 10
Build a machine learning environment natively on Windows 10 (x64)
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Build python virtual environment with virtualenv
Machine learning with python (1) Overall classification
Build Mysql + Python environment with docker
Create a virtual environment with Python!
Building a virtual environment with Python 3
Build a web application with Django
Build a python3 environment on CentOS7
Prepare Python development environment with Atom
"Scraping & machine learning with Python" Learning memo
Application development with Docker + Python + Flask
Application development using Azure Machine Learning
Build a machine learning environment on mac (pyenv, deeplearning, opencv)