:note

Python3環境の再作成

NumPyとMatplotlibをPython3環境にインストールしたかったので、その手順メモ。

すでに Homebrewで Python2とPython3がインストールされている。

% brew list | grep python
python
python3

% brew list | grep numpy
numpy


% pip2 list --format=columns
Package    Version
---------- -------
GDAL       1.11.5
nose       1.3.7
numpy      1.11.2
pip        9.0.1
setuptools 32.1.0
wheel      0.29.0


% pip3 list --format=columns
Package    Version
---------- -------
pip        9.0.1
setuptools 32.2.0
wheel      0.29.0

NumPyはすでにPython2の方にはインストールされている。

% brew deps --installed | grep python
googler: python3
python: gdbm openssl readline sqlite
python3: gdbm openssl readline sqlite xz

Python2自体は他に依存がされていないぽいので、 NumPyとGDALをPython3側にインストールして、あとでPython2はアンインストールすることにする。

% brew info numpy
numpy: stable 1.12.0 (bottled), HEAD
Package for scientific computing with Python
http://www.numpy.org
/usr/local/Cellar/numpy/1.11.2 (433 files, 9.1M) *
  Poured from bottle on 2016-10-20 at 09:28:38
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/numpy.rb
==> Requirements
Build: fortran ✘
Optional: python3 ✔
==> Options
--with-python3
	Build with python3 support
--without-python
	Build without python2 support
--HEAD
	Install HEAD version

Python3用のオプションを渡せば良さそう。

% brew uninstall numpy
Error: Refusing to uninstall /usr/local/Cellar/numpy/1.11.2
because it is required by opencv, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies numpy

OpenCVがNumPyに依存してる。

強制アンインストールもできるっぽいけど、削除してから再インストール。

% brew uninstall opencv
Uninstalling /usr/local/Cellar/opencv/2.4.13.2... (278 files, 35.8M)
% brew uninstall numpy
Uninstalling /usr/local/Cellar/numpy/1.11.2... (433 files, 9.1M)
% brew install numpy --with-python3  --without-python
.
.
.
==> python3 -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cellar/numpy/1.12.0/libexec/nose --single-version-externally-managed --record=install
==> python3 setup.py build --fcompiler=gnu95 --parallel=4 install --prefix=/usr/local/Cellar/numpy/1.12.0 --single-version-externally-managed --record=installed.tx
🍩  /usr/local/Cellar/numpy/1.12.0: 680 files, 14.0M, built in 1 minute 55 seconds

NumPyを使えるようになった。

% python3
Python 3.6.0 (default, Dec 24 2016, 08:02:28)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np
<module 'numpy' from '/usr/local/lib/python3.6/site-packages/numpy/__init__.py'>

GDAL, OpenCVの再インストール

% brew uninstall gdal
% brew install gdal --with-python3 --without-python
% brew install opencv

Matplotlibのインストール

% pip3 install matplotlib
Collecting matplotlib
  Downloading matplotlib-2.0.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (12.8MB)
    100% |████████████████████████████████| 12.8MB 75kB/s
Collecting python-dateutil (from matplotlib)
  Downloading python_dateutil-2.6.0-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 2.5MB/s
Collecting cycler>=0.10 (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Requirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python3.6/site-packages (from matplotlib)
Collecting pyparsing!=2.0.0,!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 (from matplotlib)
  Downloading pyparsing-2.1.10-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 3.1MB/s
Collecting pytz (from matplotlib)
  Downloading pytz-2016.10-py2.py3-none-any.whl (483kB)
    100% |████████████████████████████████| 491kB 1.7MB/s
Collecting six>=1.10 (from matplotlib)
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, cycler, pyparsing, pytz, matplotlib
Successfully installed cycler-0.10.0 matplotlib-2.0.0 pyparsing-2.1.10 python-dateutil-2.6.0 pytz-2016.10 six-1.10.0

Matplotlib使えるようになった、GUIアプリが立ち上がります。

% python3
Python 3.6.0 (default, Dec 24 2016, 08:02:28)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> from matplotlib.image import imread
>>>
 
comments powered by Disqus
back to top