Pillow environment construction --Virtual environment by virtualenv, interactive environment by iPython

What you want to do

--Pillow's (probably) powerful graphics processing

--Using virtualization with virtualenv, which is easy to maintain

--Easy to use iPython

Realize a Python processing environment.

Prerequisites

It is assumed that Python 3.4, pip, and virtualenv are already installed.

Building a virtual environment

Create a working directory called py3 and build a virtual environment called box01 in it.

python


mkdir py3
virtualenv  --python=python3.4 py3/box01

cd py3/box01

Enable virtual environment

python


source bin/activate

Install Pillow in virtual environment

python


pip install pillow

Install iPython and other modules in the virtual environment

python


pip install ipython3
pip install jinja2
pip install tornado
pip install pyzmq

pip install numpy
pip install matplotlib
pip install pandas
pip install scipy

pip install jsonschema #I was angry if I didn't enter later

pip install requests #Required to run iptest3

pip install mistune #Below, in iptest3, I was told that it was not included
pip install pygments
pip install pymongo
pip install sphinx

Test if iPython can run

If you install iPython3, a command called iptest3 will come with it and it will check if it can be executed.

python


iptest3

Execution result (excerpt)

python


Test suite completed for system with the following information:
IPython version: 3.0.0
IPython commit : f75fda4 (installation)
IPython package: ~/py3/box01/lib/python3.4/site-packages/IPython
Python version : 3.4.2 (default, Oct  8 2014, 13:18:07) [GCC 4.9.1]
sys.executable : ~/py3/box01/bin/python3.4
Platform       : Linux-3.16.0-31-generic-i686-with-Ubuntu-14.10-utopic

Tools and libraries available at test time:
   curses jinja2 jsonschema matplotlib mistune numpy pexpect pygments pymongo requests sphinx sqlite3 terminado tornado zmq

Tools and libraries NOT available at test time:
   casperjs phantomjs qt slimerjs

I didn't know what to do with the bottom four.

After all, the module configuration I put in was as follows. (As a result of trial and error, it seems that unnecessary modules are also included.)

python


pip freeze
Babel==1.3
Jinja2==2.7.3
MarkupSafe==0.23
Pillow==2.7.0
Pygments==2.0.2
Sphinx==1.3.1
WebOb==1.4
WebTest==2.0.18
alabaster==0.7.2
beautifulsoup4==4.3.2
certifi==14.05.14
docutils==0.12
gp.recipe.phantomjs==2.0.0.0
hexagonit.recipe.download==1.7
ipython==3.0.0
jsonschema==2.4.0
matplotlib==1.4.3
mistune==0.5.1
nose==1.3.4
numpy==1.9.2
pandas==0.15.2
ptyprocess==0.4
pymongo==2.8
pyparsing==2.0.3
python-dateutil==2.4.1
pytz==2014.10
pyzmq==14.5.0
requests==2.6.0
scipy==0.15.1
six==1.9.0
snowballstemmer==1.2.0
sphinx-rtd-theme==0.1.7
terminado==0.5
tornado==4.1
waitress==0.8.9
webtest-casperjs==0.1
zc.buildout==2.3.1
zc.recipe.egg==2.0.1

iPython server settings

Create profile

python


ipython3 profile create py3nb

Create password string

Launch ipyton3 from the console

python


ipyton3

python


from IPython.lib import passwd
passwd()

(Enter the password you want to set twice)

'sha1: ' Is output. Write this in ipython_notebook_config.py.

Once exit from ipyton3

python


exit()

Edit Notebook configuration file

Create a new setting file python_notebook_config.py

python


vi ~/.ipython/profile_py3nb/ipython_notebook_config.py

py3:~/.ipython/profile_py3nb/ipython_notebook_config.py


c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 9999 
c.NotebookApp.password = 'sha1:<String>' # 先ほど作成したパスワードString

There is a possibility that this area is wrong because I worked with a lot of momentum.

Setting the execution script at startup

python


vi ~/.ipython/profile_py3nb/startup/00-startup.py

py3:~/.ipython/profile_py3nb/startup/00-startup.py


#! /usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os
import readline
import numpy as np
import scipy as sp
import pandas as pd
import matplotlib.pyplot as plt

# EOF

Launching a notebook

python


ipython3 notebook --profile=py3nb

It seems that the --pylab = inline option has been abolished.

Access from browser http://<ノートブックサーバーのIPアドレス>:9999/

Enter your password and put it in your notebook.

Operation check

Below, run on iPython notebook

It seems that I have to do this first.

python


%pylab inline

1 First, check the matplotlib plot

(Previously confirmed operation)

python


x = np.arange(-3, 3, .1)
y = np.sin(x)
plt.plot(x, y)

2 Pillow operation check

Pillow import

python


from PIL import Image

Load image (upload image file to server in advance)

python


img = np.array( Image.open('<Image file name>') )

Image display. It doesn't seem to be displayed in img.show ().

python


plt.imshow(img)

Run screenshot sc20150319.PNG

Let's use

Since the current directory seems to be messy, create a working directory called ipy under ~ / py3 / box01, and under that in-image / (for input) out-image / (for output) work-image / (for work) I create a directory called, and put the image files in this directory.

↓ I created a shell script for starting like this.

run_ipy.sh


#! /bin/bash

source ~/py3/box01/bin/activate
cd ~/py3/box01/ipy
~/py3/box01/bin/ipython3 notebook --profile=py3nb
# EOF

Try using Pillow on iPython (Part 1) --Qiita

Try using Pillow on iPython (Part 2) --Qiita

Try Pillow on iPython (Part 3) --Qiita

Recommended Posts

Pillow environment construction --Virtual environment by virtualenv, interactive environment by iPython
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Build python virtual environment with virtualenv
Python virtual environment construction (2017 version) pyenv and pyenv-virtualenv and virtualenv and virtualenv wrapper and pyvenv and venv
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Work in a virtual environment with Python virtualenv.
Python 3.x environment construction by Pyenv (CentOS, Ubuntu)
From Python environment construction to virtual environment construction with anaconda
DeepIE3D environment construction
Emacs-based environment construction
Linux environment construction
Python environment construction
Environment construction (python)
django environment construction
CodeIgniter environment construction
python environment construction
Python --Environment construction
Python environment construction
Golang environment construction
python environment construction
Word2vec environment construction
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Build a python virtual environment with virtualenv and virtualenvwrapper
Data analysis environment construction with Python (IPython notebook + Pandas)
Pepper-kun remote control environment construction with Docker + IPython Notebook
Build a python virtual environment with virtualenv and virtualenvwrapper
Report environment construction by python (matplotlib, pandas, sphinx) + wkhtmltopdf
Reflect the virtual environment created by virtualenv or conda in the IntelliJ IDEA (PyCharm) project (memo)