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.
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
pip install virtualenv
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
Python installation: Miniconda
Install pip: conda install pip
Install virtualenv: pip install virtualenv
Python 3.5-based miniconda requires Visual C ++ runtime for Visual Studio 2015. Note that if this is not installed, an error will occur during installation (as of November 13, 2015. It should be supported soon. [Python 3.5 missing VCRUNTIME140.dll](https://github.com/ContinuumIO/anaconda- issues / issues / 443))).
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
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.
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.
koudaiii prepared Docker and shiraco prepared Ansible, so you can put it in.
koudaiii/ml-handson shiraco/ansible_ipython_machineleaning_bootstrap_conda
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