2015年10月28日水曜日

代官山散歩♪

目的地がない状態でただただ散歩するより、目的地を決めつつも寄り道しながら散歩するのが好きです。

事情があり当日中に更新できなかったので、先日のことになりますが代官山を歩いてきました。

疲れてたため、お昼頃起きて、お昼を食べたあとコンタクトを買ってから代官山へ向かったので、夕方頃からの出発でした。

一応目的地はquadroというお店に行くことでした。洋服の下見をするためです。

以前、恵比寿でバッグを購入したときに系列店として紹介されていたお店です。

大手で買うのもいいけれど、セレクトショップというものも行ってみたいなと思っていたので、冬を前にして手始めに紹介されていた店に行こうとしていました。

特に理由はないのですが、バッグを購入した店が恵比寿にあったので、散歩も兼ねて恵比寿から歩いてみました。

そうすると、恵比寿から代官山近辺はお洒落なお店がたくさんありました。

独特の雰囲気をもっているお洒落な街でした。銀座もお洒落だけど、それとはまた違う雰囲気です。

歩いている人たちも洗練されていました。

高級感があるけど、居づらくないというか。もっと落ち着いた雰囲気といったところでしょうか。ここに住んでみたい〜!!

蔦屋書店の場所もどこにあるか知らなかったのですが、今日たまたま前を通って場所を知りました。

個人的に気になったのはと紅茶専門店のルピシアという店とCarbootsという洋服屋さんとJay Haideというブランドを扱っているバイオリン屋さん?です。

Carbootsはたまたま前を通っただけで、どんな服を売っているのか全然みてはいませんが、帰って調べてみたら女性向けの洋服屋さんなのか。。。?

セレクトショップがかなりたくさんあることを発見したので、今日は夕方からだったのであまり見て回れませんでしたが、時間のあるときにまた来てみたいです。

2015年10月11日日曜日

英検を受けてきました。

今日は英検を受けに行ってきました。

2級。レベル的には、高校卒業程度ってことらしいので、今更な感ありますが。

でも実際、会場は年齢問わずいろんな人がいました。

中学の時に3級を取って以来、全く受けておらず。資格とかもなにもないので、手始めに受けてみようかなと思って受けてみました。

今回、本当に特に英検に特化した対策はなにもせずに行きました。
普段から多読は行っているし、TOEFL対策などはガッツリやったこともあるので、その状態でどんな感じになるのか試してみました。

想像してたよりは簡単でした。想像してたよりは、ですが。

もっと手も足もでないかと思ってました。

今回合格しているかどうかは微妙な手応えですが、もし落ちていたとしても次回十分に対策をすればいける気がしました。

ところどころ、意味があやふやな単語もちらほらあったので、そこは今後の課題ですね。

ちなみに、今月はTOEICも受ける予定。今更特化した対策はするつもりはないですが、英語には触れていようと思います。

2015年10月7日水曜日

csvファイルの扱い1---スプレッドシートやExcelとの絡みにて---

csvファイルについて調べたことを書いてみようと思います。

もともとの目標は、pythonなどのプログラミング言語でcsvファイルを扱う方法について調べようと思っていたのですが、もう少し基本的なことまで遡ってcsvファイルの扱い方について調べてみました。

csvファイルとは

そもそもなんなのか、という部分については検索すれば丁寧な解説がたくさんでているので、そちらへ譲ります。

要するに、windowsでいえばメモ帳、Macでいえばテキストエディタとかに書かれていて、カンマで区切られて書かれている

こういうファイルです。

これを、例えばExcelとか、もともとは表形式で作成したデータを、テキストファイル形式にして、他のアプリケーションとやりとりをしやすくします。

表形式のデータだと、ExcelとExcelの間のやりとりなら、まだいいとしても、他のソフトとやりとりをしようと思うと、ファイルの形式が合わず、うまくいきません。

データそのもの(つまりExcelの場合でいえば、各セルに入力されているデータ)以外にも、体裁を整えるための余分なデータがくっついてしまっているので。

で、データの基本的な部分だけ残して作ったものが、csvファイルです。

スプレッドシート→csvファイルの作成

Excelをあまり使ったことがないのでわかりませんが、おそらくExcelでも基本的には同じだと思います。

ここでは、Googleドライブのスプレッドシートからcsvファイルを作成します。

サンプル用のデータとして、次のようなデータを用意します。




データを作成したら、画面左上の「ファイル」をクリックし、「形式を指定してダウンロード」→「カンマ区切りの値(.csv、現在のシート)」を選んでクリックします。



クリックをすると、すぐにダウンロードされます。

普段ダウンロードされたデータが入る場所をみると、「.csv」のファイルができています。

今はMacを使っているので、「ダウンロード」というフォルダの中に入りました。

そのままcsvのデータを開くと、Excelとかデフォルトで指定されているソフトで開かれてしまうと思うので、どのソフトで開くかを指定します。

Macの場合であれば、


ここをクリックすると、


「このアプリケーションを開く」にマウスを合わせ、


「テキストエディタ」をクリックします。

そうすると、テキストエディタで

このように書かれたデータが表示されます。これがcsvファイルです。

csvファイル→スプレッドシート

具体的な操作手順に関してはいろいろあると思いますが、今回は次のような方法でいきます。

新規にスプレッドシートを開き、画面左上のメニューから「インポート」を選びます。



新しく出てくる画面で、アップロードを選び、画面の指示通り、該当のファイルを直接ドラッグするか、パソコンのから該当のファイルを選んで指定します。

そうすると、左下の「選択」のボタンが押せるようになるので、クリックします。


そうすると次のような画面がでます。




ここで操作を選びます。

インポート操作のところは、
  • 新しいスプレッドシートを作成する
    →今開いているスプレッドシートとは全く別に新規にスプレッドシートを開き、そこにcsvファイルを読み込み。

  • 新しいシートを挿入する。
    →現在開いているスプレッドシートで、新しいシートを追加し新しく追加したシートにcsvファイルを読み込み。

  • スプレッドシートを置き換えする。
    →現在のシートにそのままcsvファイルを流し込む。(それ以下の三つと混同しやすい表現ですが。。。)
それ以下三つの選択肢はやや説明が面倒なのでしません。

区切り文字の方は、文字通り「データの区切りの記号はなににしているか」です。
ここは「自動的に検出する」か、「カンマ」にします。csvですのでね。

「タブ」もあるのは、世の中にはcsv(Camma Separeted Value)に対して、「タブ」で区切られてるtsv(Tab Separated Value)なるものもあるからです。

それで読み込みをすると、こうなって無事読み込めます。




ちなみにcsvファイルを読み込むのに、区切り文字に「タブ」を選択すると、次のようになります。



これは、区切り文字は「タブ」と指定しているので、「タブ」がデータの区切りになっているわけです。

つまり、タブが現れるまでは一塊のデータです。

一方、csvと同じように改行コードがくれば、行が変わります。

csvファイルをtsvとして読み込むと、タブが来る前に改行コードが来ているので、一行目が、丸々ひとつのデータをして扱われ、改行コードにて次の行に読み込まれているわけです。

次回は、csvをpythonやCで扱う方法について書いてみようと思います。

2015年9月23日水曜日

Macでpython3の環境構築8---NLTKのインストール2---

前回の続きです。
(前回:Macでpython3の環境構築7---NLTKのインストール1---

nltk.download()とコマンドを打ってもうまくいかないというお話でした。

これは次のようなコマンドでも代替できるようです。

hiroshi-no-MacBook-Air:~ hiroshi$ python3 -m nltk.downloader book                
#  「python3 -m nltk.downloader book」と打ってreturnを押す。

そうすると、次のような処理が始まります。

[nltk_data] Downloading collection 'book'
[nltk_data]    |
[nltk_data]    | Downloading package abc to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package abc is already up-to-date!
[nltk_data]    | Downloading package brown to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package brown is already up-to-date!
[nltk_data]    | Downloading package chat80 to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package chat80 is already up-to-date!
[nltk_data]    | Downloading package cmudict to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package cmudict is already up-to-date!
[nltk_data]    | Downloading package conll2000 to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package conll2000 is already up-to-date!
[nltk_data]    | Downloading package conll2002 to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package conll2002 is already up-to-date!
[nltk_data]    | Downloading package dependency_treebank to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package dependency_treebank is already up-to-date!
[nltk_data]    | Downloading package genesis to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package genesis is already up-to-date!
[nltk_data]    | Downloading package gutenberg to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package gutenberg is already up-to-date!
[nltk_data]    | Downloading package ieer to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package ieer is already up-to-date!
[nltk_data]    | Downloading package inaugural to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package inaugural is already up-to-date!
[nltk_data]    | Downloading package movie_reviews to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package movie_reviews is already up-to-date!
[nltk_data]    | Downloading package nps_chat to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package nps_chat is already up-to-date!
[nltk_data]    | Downloading package names to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package names is already up-to-date!
[nltk_data]    | Downloading package ppattach to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package ppattach is already up-to-date!
[nltk_data]    | Downloading package reuters to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Package reuters is already up-to-date!
[nltk_data]    | Downloading package senseval to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/senseval.zip.
[nltk_data]    | Downloading package state_union to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/state_union.zip.
[nltk_data]    | Downloading package stopwords to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/stopwords.zip.
[nltk_data]    | Downloading package swadesh to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/swadesh.zip.
[nltk_data]    | Downloading package timit to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/timit.zip.
[nltk_data]    | Downloading package treebank to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/treebank.zip.
[nltk_data]    | Downloading package toolbox to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/toolbox.zip.
[nltk_data]    | Downloading package udhr to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/udhr.zip.
[nltk_data]    | Downloading package udhr2 to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/udhr2.zip.
[nltk_data]    | Downloading package unicode_samples to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/unicode_samples.zip.
[nltk_data]    | Downloading package webtext to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/webtext.zip.
[nltk_data]    | Downloading package wordnet to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/wordnet.zip.
[nltk_data]    | Downloading package wordnet_ic to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/wordnet_ic.zip.
[nltk_data]    | Downloading package words to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/words.zip.
[nltk_data]    | Downloading package maxent_treebank_pos_tagger to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping taggers/maxent_treebank_pos_tagger.zip.
[nltk_data]    | Downloading package maxent_ne_chunker to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping chunkers/maxent_ne_chunker.zip.
[nltk_data]    | Downloading package universal_tagset to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping taggers/universal_tagset.zip.
[nltk_data]    | Downloading package punkt to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping tokenizers/punkt.zip.
[nltk_data]    | Downloading package book_grammars to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping grammars/book_grammars.zip.
[nltk_data]    | Downloading package city_database to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping corpora/city_database.zip.
[nltk_data]    | Downloading package tagsets to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |   Unzipping help/tagsets.zip.
[nltk_data]    | Downloading package panlex_swadesh to
[nltk_data]    |     /Users/hiroshi/nltk_data...
[nltk_data]    |
[nltk_data]  Done downloading collection book
hiroshi-no-MacBook-Air:~ hiroshi$


では、次にそのまま、

hiroshi-no-MacBook-Air:~ hiroshi$ from nltk.book import *             
 #       $のあとにいきなり「from nltk.book import *」と打ってもうまくはいかない。

としても。。。

from: can't read /var/mail/nltk.book
hiroshi-no-MacBook-Air:~ hiroshi$

と返されうまくいきません。

今度はこうしてみます。

hiroshi-no-MacBook-Air:~ hiroshi$ python3

そうすると、こうなります。

Python 3.4.3 (default, Aug 11 2015, 08:57:25)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

また入力の待ち状態になるので、続けて二つコマンドを打ってみます。

>>> import nltk      #  「import nltk」と打ってreturnを押す。
>>> text1               #    続けてtext1と打ってreturnを押す。


それでも、やはりこうなってしまい失敗。

Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'text1' is not defined
>>>

今度は、こうしてみます。
>>> from nltk.book import *         #  「from nltk.book import *」と打ってreturnを押す。

そうすると次のようになります。

*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>>

最後に、「text1」と打って

>>> text1
<Text : Moby Dick by Herman Melvile 1851 >
>>>

となり、なんとか成功しました。

まとめとしては、「python3 -m nltk.downloader book」を行ったあとは
  1. python3  とコマンドを打つ。
  2. import nltk とコマンドを打つ。
  3. from nltk.book import * とコマンドを打つ。
  4. 最後にtext1と打って、上記のように表示されれば成功。
となります。

2015年9月22日火曜日

Macでpython3の環境構築7---NLTKのインストール1---

今回はNLTKをインストールしていきます。
まず、NLTK自体のインストールはすぐできます。
次のようにコマンドを打ちます。

hiroshi-no-MacBook-Air:~ hiroshi$ sudo pip3 install -u nltk          #       「sudo  pip3 install -u nltk」と打ってreturnを押す。

そうすると、パスワードを求められるので入力します。今までも出てきたので同じことの繰り返しになりますが、打っても入力できているようには見えませんが、きちんと認識はされています。

Password:          #  自分のPCのパスワードを入力。入力できているようには見えないけど、きちんと認識はされています。

そうすると以下のような処理がはしり、NLTKのインストールは終わりです。

The directory '/Users/hiroshi/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been
 disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The directory '/Users/hiroshi/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache
 has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting nltk
  Downloading nltk-3.0.5.tar.gz (1.0MB)
    100% |████████████████████████████████| 1.0MB 325kB/s
Requirement already up-to-date: six>=1.9.0 in /usr/local/lib/python3.4/site-packages (from nltk)
Building wheels for collected packages: nltk
  Running setup.py bdist_wheel for nltk
  Stored in directory: /Users/hiroshi/Library/Caches/pip/wheels/f6/ef/3d/039e21095c9845e948931918734aa6c05df4d72f09
a3132c69
Successfully built nltk
Installing collected packages: nltk
Successfully installed nltk-3.0.5

hiroshi-no-MacBook-Air:~ hiroshi$ 


これで、NLTKのインストールは完了。
このあと、サンプルデータのインストールになりますが、これが少しやっかいかも。

続いて、次のようにコマンドを打ちます。
hiroshi-no-MacBook-Air:~ hiroshi$ python3        #「python3」と打ってreturnを押す。

そうすると次のようになり、また入力の待ち状態になります。

Python 3.4.3 (default, Aug 11 2015, 08:57:25)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>          #入力の待ち状態

そこにまたコマンドをうちます。

>>> import nltk       #「import nltk」と打ってreturnを押す。
>>> nltk.download()     #そうするとまた入力待ちになるので、続けて「nltk.download()」と打ってreturnを押す。

そうすると、
ターミナルの方は、
showing info http://www.nltk.org/nltk_data/

と表示されると同時に 新しい画面が立ち上がります。
で、上の画面はallが選ばれていますが、bookを選んで左下のDownloadを押します。
そうすると、/User/hiroshi/の中に、nltk_dataというフォルダが作成されます。
これでうまくいくはずなのですが、エラーが出てしまいました。

そのとき、ターミナル上は、こうなっています。

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1533, in __call__
    return self.func(*args)
  File "/usr/local/lib/python3.4/site-packages/nltk/downloader.py", line 1569, in _download
    return self._download_threaded(*e)
  File "/usr/local/lib/python3.4/site-packages/nltk/downloader.py", line 1836, in _download_threaded
    assert self._download_msg_queue == []
AssertionError
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1533, in __call__
    return self.func(*args)
  File "/usr/local/lib/python3.4/site-packages/nltk/downloader.py", line 1569, in _download
    return self._download_threaded(*e)
  File "/usr/local/lib/python3.4/site-packages/nltk/downloader.py", line 1836, in _download_threaded
    assert self._download_msg_queue == []
AssertionError

このinvalid argumentというのをそのまま検索してみると、引数が不正、無効、とのこと。
一体なんのことやら。。。
わかる方がいたら教えてください。

よくわからないので、新しく出た画面の方はバツとじをしてしまいました。
そうすると、Trueとターミナル上には表示されます。

#####先ほどの続きから。中略。########
  File "/usr/local/lib/python3.4/site-packages/nltk/downloader.py", line 1569, in _download
    return self._download_threaded(*e)
  File "/usr/local/lib/python3.4/site-packages/nltk/downloader.py", line 1836, in _download_threaded
    assert self._download_msg_queue == []
AssertionError
True        #バツとじをするTrueと表示される。

全然うまくいっている感じはしないけれど、(そもそもエラーでたし)念のためうまくいっているかどうか確認をすることに。
「from nltk.book import *」と打って、「text1」と打って、「<Text: Moby Dick by Herman Melville 1851>」と表示されればうまくいったかどうかの確認らしい。

先ほどのところでTrueとでたあとはまた入力待ちのような状態になっているので、次ようにまた打ち込みます。
>>> from nltk.book import *       #    「from nltk.book import *」と打ってreturnを押す。

そうするとつぎのようになります。
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/nltk/corpus/util.py", line 63, in __load
    try: root = nltk.data.find('corpora/%s' % zip_name)
  File "/usr/local/lib/python3.4/site-packages/nltk/data.py", line 624, in find
    raise LookupError(resource_not_found)
LookupError:
**********************************************************************
  Resource 'corpora/webtext.zip/webtext/' not found.  Please use
  the NLTK Downloader to obtain the resource:  >>> nltk.download()
  Searched in:
    - '/Users/hiroshi/nltk_data'
    - '/usr/share/nltk_data'
    - '/usr/local/share/nltk_data'
    - '/usr/lib/nltk_data'
    - '/usr/local/lib/nltk_data'
**********************************************************************

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.4/site-packages/nltk/book.py", line 34, in 
    text6 = Text(webtext.words('grail.txt'), name="Monty Python and the Holy Grail")
  File "/usr/local/lib/python3.4/site-packages/nltk/corpus/util.py", line 99, in __getattr__
    self.__load()
  File "/usr/local/lib/python3.4/site-packages/nltk/corpus/util.py", line 64, in __load
    except LookupError: raise e
  File "/usr/local/lib/python3.4/site-packages/nltk/corpus/util.py", line 61, in __load
    root = nltk.data.find('corpora/%s' % self.__name)
  File "/usr/local/lib/python3.4/site-packages/nltk/data.py", line 624, in find
    raise LookupError(resource_not_found)
LookupError:
**********************************************************************
  Resource 'corpora/webtext' not found.  Please use the NLTK
  Downloader to obtain the resource:  >>> nltk.download()
  Searched in:
    - '/Users/hiroshi/nltk_data'
    - '/usr/share/nltk_data'
    - '/usr/local/share/nltk_data'
    - '/usr/lib/nltk_data'
    - '/usr/local/lib/nltk_data'
**********************************************************************
>>>


やはりうまくいっている感じは全然しないけれど、続けます。
>>> text8     #「text8」と打ってreturnを押す。

が、やはり
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'text8' is not defined

となってしまいます。「NameError: name 'text8' is not defined」とか言われてるしね。。。
text5とかtext1とかでやっても同じです。

しらべてみると、「nltk.download()」のくだりは別の方法でもできるらしい。
結局今回のエラーについて原因はよくわからないままでしたが、あとまわしにして別の方法で、試してみたいと思います。それは次回。

2015年9月18日金曜日

Macでpython3の環境構築6---Matplotlibのインストール3---

Macでpython3の環境構築4---Matplotlibのインストール1」と「Macでpython3の環境構築4---Matplotlibのインストール2」でzlibがない状態でMatplotlibをインストールしました。

しかし、Networkxのプログラムを実行すると、グラフのノードにラベルがつきませんでした。
zlibの有無が原因ではないだろうことは、一応既に予想はついているのですが、念のためにzlibがある状態でなにか変化があるのかも確認してみます。

ということで、まずはzlibから始まりMatplotlibのインストールまでの流れをもう一度なぞります。

zlibのインストール

まず、zlibのページ
へアクセスします。


最新のバージョンをクリックすると、次の画面になります。


末尾が「.tar.gz」で終わっているものをクリックするとダウンロードが始まります。

ダウンロードし解凍すると、zlib-●-●-●というフォルダができます。(●のところはダウンロードしたバージョンによってかわる。)

今回は、zlib-1.2.7をダウンロードしました。

そして次のように打って、カレントディレクトリに移動します。

hiroshi-no-MacBook-Air:~ hiroshi$ cd Downloads     #  「cd Downloads」と打ってreturnを押す。
hiroshi-no-MacBook-Air:Downloads hiroshi$ cd zlib-●-●-●  #      続けて「cd zlib-●-●-●」と打ってreturnを押す。●のところはダウンロードしたバージョンによって違う。


続けて、次のようにコマンドを打ちます。
hiroshi-no-MacBook-Air:zlib-1.2.7 hiroshi$ ./configure      #  「./configure」と打ってreturnを押す。

そうすると次のような処理が始まります。

Checking for gcc...
Checking for shared library support...
Building shared library libz.1.2.7.dylib with gcc.
Checking for off64_t... No.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
Looking for a four-byte integer type... Found.
hiroshi-no-MacBook-Air:zlib-1.2.7 hiroshi$ 

終わったら、続けて

hiroshi-no-MacBook-Air:zlib-1.2.7 hiroshi$ make      #  「make」と打ってreturnを押す。


とします。
そうすると、次ような処理が走ります。

gcc -O3  -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -O3  -DHAVE_HIDDEN   -c -o adler32.o adler32.c
gcc -O3  -DHAVE_HIDDEN   -c -o crc32.o crc32.c
gcc -O3  -DHAVE_HIDDEN   -c -o deflate.o deflate.c
gcc -O3  -DHAVE_HIDDEN   -c -o infback.o infback.c
gcc -O3  -DHAVE_HIDDEN   -c -o inffast.o inffast.c
gcc -O3  -DHAVE_HIDDEN   -c -o inflate.o inflate.c
gcc -O3  -DHAVE_HIDDEN   -c -o inftrees.o inftrees.c
gcc -O3  -DHAVE_HIDDEN   -c -o trees.o trees.c
gcc -O3  -DHAVE_HIDDEN   -c -o zutil.o zutil.c
gcc -O3  -DHAVE_HIDDEN   -c -o compress.o compress.c
gcc -O3  -DHAVE_HIDDEN   -c -o uncompr.o uncompr.c
gcc -O3  -DHAVE_HIDDEN   -c -o gzclose.o gzclose.c
gcc -O3  -DHAVE_HIDDEN   -c -o gzlib.o gzlib.c
gcc -O3  -DHAVE_HIDDEN   -c -o gzread.o gzread.c
gcc -O3  -DHAVE_HIDDEN   -c -o gzwrite.o gzwrite.c
/usr/bin/libtool -o libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
gcc -O3  -DHAVE_HIDDEN -o example example.o -L. libz.a
gcc -O3  -DHAVE_HIDDEN -I. -c -o minigzip.o test/minigzip.c
gcc -O3  -DHAVE_HIDDEN -o minigzip minigzip.o -L. libz.a
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/adler32.o adler32.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/crc32.o crc32.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/deflate.o deflate.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/infback.o infback.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/inffast.o inffast.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/inflate.o inflate.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/inftrees.o inftrees.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/trees.o trees.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/zutil.o zutil.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/compress.o compress.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/uncompr.o uncompr.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/gzclose.o gzclose.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/gzlib.o gzlib.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/gzread.o gzread.c
gcc -O3  -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/gzwrite.o gzwrite.c
gcc -dynamiclib -install_name /usr/local/lib/libz.1.dylib -compatibility_version 1 -current_version 1.2.7 -O3  -fPIC -DHAVE_HIDDEN -o libz.1.2.7.dylib adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo  -lc
rm -f libz.dylib libz.1.dylib
ln -s libz.1.2.7.dylib libz.dylib
ln -s libz.1.2.7.dylib libz.1.dylib
gcc -O3  -DHAVE_HIDDEN -o examplesh example.o -L. libz.1.2.7.dylib
gcc -O3  -DHAVE_HIDDEN -o minigzipsh minigzip.o -L. libz.1.2.7.dylib
hiroshi-no-MacBook-Air:zlib-1.2.7 hiroshi$


さらに続けて、

hiroshi-no-MacBook-Air:zlib-1.2.7 hiroshi$ sudo make install      #    「sudo make install」と打ってreturnを押す。

とします。 すると、パスワードを求められるので、自分のPCへログインするときのパスワードを入力します。入力できているようには見えませんが、入力できているので気にしない。

Password:        #自分のPCのパスワードを入力。そしてreturnを押す。入力できているようには見えないけど、きちんと認識はされています。

パスワードを入力すると、次のような処理が走ります。

cp libz.a /usr/local/lib
chmod 644 /usr/local/lib/libz.a
cp libz.1.2.7.dylib /usr/local/lib
chmod 755 /usr/local/lib/libz.1.2.7.dylib
cp zlib.3 /usr/local/share/man/man3
chmod 644 /usr/local/share/man/man3/zlib.3
cp zlib.pc /usr/local/lib/pkgconfig
chmod 644 /usr/local/lib/pkgconfig/zlib.pc
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h
hiroshi-no-MacBook-Air:zlib-1.2.7 hiroshi$ 


freetype2のインストール(zlibがある状態で)

続いて、freetype2をzlibがある状態でイントール。やること自体は、以前と同じです。
まず。カレントディレクトリに移動。

hiroshi-no-MacBook-Air:~ hiroshi$ cd Downloads        #    「cd Downloads」と打ってreturnを押す。
hiroshi-no-MacBook-Air:Downloads hiroshi$ cd freetype-2.6 2     #     続いて、「cd freetype-2.6 2」と打ってreturnを押す。


そして、続けて次のように打ちます。

hiroshi-no-MacBook-Air:freetype-2.6 hiroshi$ ./configure       #   「./configure」と打ってreturnを押す。


そうすると、また長いですが、次のようになります。

FreeType build system -- automatic system detection

The following settings are used:

  platform                    unix
  compiler                    cc
  configuration directory     ./builds/unix
  configuration rules         ./builds/unix/unix.mk

If this does not correspond to your system or settings please remove the file
`config.mk' from this directory then read the INSTALL file for help.

Otherwise, simply type `/Applications/Xcode.app/Contents/Developer/usr/bin/make' again to build the library,
or `/Applications/Xcode.app/Contents/Developer/usr/bin/make refdoc' to build the API reference (this needs python >= 2.6).

cd builds/unix; \
      CONFIG_SHELL="/bin/sh" \
        /bin/sh ./configure
checking build system type... x86_64-apple-darwin14.5.0
checking host system type... x86_64-apple-darwin14.5.0
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for pkg-config... no
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm
checking the name lister (/usr/bin/nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking how to convert x86_64-apple-darwin14.5.0 file names to x86_64-apple-darwin14.5.0 format... func_convert_file_noop
checking how to convert x86_64-apple-darwin14.5.0 file names to toolchain format... func_convert_file_noop
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for objdump... no
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking command to parse /usr/bin/nm output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin14.5.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for rmdir... rmdir
checking for a BSD-compatible install... /usr/bin/install -c
checking for ANSI C header files... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking size of int... 4
checking size of long... 8
checking whether cpp computation of bit length in ftconfig.in works... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... yes
checking for working mmap... yes
checking whether munmap is declared... yes
checking for munmap's first parameter type... void *
checking for memcpy... yes
checking for memmove... yes
checking gcc compiler flag -ansi to assure ANSI C works correctly... ok, add it to XX_ANSIFLAGS
checking for ZLIB... no
checking for gzsetparams in -lz... yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking for BZIP2... no
checking for BZ2_bzDecompress in -lbz2... yes
checking bzlib.h usability... yes
checking bzlib.h presence... yes
checking for bzlib.h... yes
checking for LIBPNG... no
checking for libpng-config... no
checking for HARFBUZZ... no
configure: creating ./config.status
config.status: creating unix-cc.mk
config.status: creating unix-def.mk
config.status: creating ftconfig.h
config.status: executing libtool commands
configure:

Library configuration:
  external zlib: yes (autoconf test)
  bzip2:         yes (autoconf test)
  libpng:        no
  harfbuzz:      no

make: Nothing to be done for `unix'.

hiroshi-no-MacBook-Air:freetype-2.6 hiroshi$

続いて、またコマンドを打ちます。

hiroshi-no-MacBook-Air:freetype-2.6 hiroshi$ make        #   「make」と打ってreturnを押す。


すると、過去に一度行っているので、特に処理ははしらず次のようなメッセージがでます。

make: Nothing to be done for `all'.
hiroshi-no-MacBook-Air:freetype-2.6 hiroshi$


さらに、続けます。

hiroshi-no-MacBook-Air:freetype-2.6 hiroshi$ sudo make install      #   「sudo make install」と打ってreturnを押す。

すると、またパスワードを求められるので、自分のPCのパスワードを入力します。

Password:       #   何度も繰り返しになりますが、入力されているようには見えませんがきちんと認識はされています。

すると、次のような処理が始まります。

./builds/unix/mkinstalldirs /usr/local/lib                      \
                         /usr/local/lib/pkgconfig            \
                         /usr/local/include/freetype2/config \
                         /usr/local/bin                      \
                         /usr/local/share/aclocal             \
                         /usr/local/share/man/man1
./builds/unix/libtool --mode=install /usr/bin/install -c                             \
                                  /Users/hiroshi/Downloads/freetype-2.6/objs/libfreetype.la /usr/local/lib
libtool: install: /usr/bin/install -c /Users/hiroshi/Downloads/freetype-2.6/objs/.libs/libfreetype.6.dylib /usr/local/lib/libfreetype.6.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libfreetype.6.dylib libfreetype.dylib || { rm -f libfreetype.dylib && ln -s libfreetype.6.dylib libfreetype.dylib; }; })
libtool: install: /usr/bin/install -c /Users/hiroshi/Downloads/freetype-2.6/objs/.libs/libfreetype.lai /usr/local/lib/libfreetype.la
libtool: install: /usr/bin/install -c /Users/hiroshi/Downloads/freetype-2.6/objs/.libs/libfreetype.a /usr/local/lib/libfreetype.a
libtool: install: chmod 644 /usr/local/lib/libfreetype.a
libtool: install: ranlib /usr/local/lib/libfreetype.a
for P in /Users/hiroshi/Downloads/freetype-2.6/include/freetype.h /Users/hiroshi/Downloads/freetype-2.6/include/ft2build.h /Users/hiroshi/Downloads/freetype-2.6/include/ftadvanc.h /Users/hiroshi/Downloads/freetype-2.6/include/ftautoh.h /Users/hiroshi/Downloads/freetype-2.6/include/ftbbox.h /Users/hiroshi/Downloads/freetype-2.6/include/ftbdf.h /Users/hiroshi/Downloads/freetype-2.6/include/ftbitmap.h /Users/hiroshi/Downloads/freetype-2.6/include/ftbzip2.h /Users/hiroshi/Downloads/freetype-2.6/include/ftcache.h /Users/hiroshi/Downloads/freetype-2.6/include/ftcffdrv.h /Users/hiroshi/Downloads/freetype-2.6/include/ftchapters.h /Users/hiroshi/Downloads/freetype-2.6/include/ftcid.h /Users/hiroshi/Downloads/freetype-2.6/include/fterrdef.h /Users/hiroshi/Downloads/freetype-2.6/include/fterrors.h /Users/hiroshi/Downloads/freetype-2.6/include/ftfntfmt.h /Users/hiroshi/Downloads/freetype-2.6/include/ftgasp.h /Users/hiroshi/Downloads/freetype-2.6/include/ftglyph.h /Users/hiroshi/Downloads/freetype-2.6/include/ftgxval.h /Users/hiroshi/Downloads/freetype-2.6/include/ftgzip.h /Users/hiroshi/Downloads/freetype-2.6/include/ftimage.h /Users/hiroshi/Downloads/freetype-2.6/include/ftincrem.h /Users/hiroshi/Downloads/freetype-2.6/include/ftlcdfil.h /Users/hiroshi/Downloads/freetype-2.6/include/ftlist.h /Users/hiroshi/Downloads/freetype-2.6/include/ftlzw.h /Users/hiroshi/Downloads/freetype-2.6/include/ftmac.h /Users/hiroshi/Downloads/freetype-2.6/include/ftmm.h /Users/hiroshi/Downloads/freetype-2.6/include/ftmodapi.h /Users/hiroshi/Downloads/freetype-2.6/include/ftmoderr.h /Users/hiroshi/Downloads/freetype-2.6/include/ftotval.h /Users/hiroshi/Downloads/freetype-2.6/include/ftoutln.h /Users/hiroshi/Downloads/freetype-2.6/include/ftpfr.h /Users/hiroshi/Downloads/freetype-2.6/include/ftrender.h /Users/hiroshi/Downloads/freetype-2.6/include/ftsizes.h /Users/hiroshi/Downloads/freetype-2.6/include/ftsnames.h /Users/hiroshi/Downloads/freetype-2.6/include/ftstroke.h /Users/hiroshi/Downloads/freetype-2.6/include/ftsynth.h /Users/hiroshi/Downloads/freetype-2.6/include/ftsystem.h /Users/hiroshi/Downloads/freetype-2.6/include/fttrigon.h /Users/hiroshi/Downloads/freetype-2.6/include/ftttdrv.h /Users/hiroshi/Downloads/freetype-2.6/include/fttypes.h /Users/hiroshi/Downloads/freetype-2.6/include/ftwinfnt.h /Users/hiroshi/Downloads/freetype-2.6/include/t1tables.h /Users/hiroshi/Downloads/freetype-2.6/include/ttnameid.h /Users/hiroshi/Downloads/freetype-2.6/include/tttables.h /Users/hiroshi/Downloads/freetype-2.6/include/tttags.h /Users/hiroshi/Downloads/freetype-2.6/include/ttunpat.h ; do                  \
          /usr/bin/install -c -m 644                           \
            $P /usr/local/include/freetype2 ; \
        done
for P in /Users/hiroshi/Downloads/freetype-2.6/include/config/ftconfig.h /Users/hiroshi/Downloads/freetype-2.6/include/config/ftheader.h /Users/hiroshi/Downloads/freetype-2.6/include/config/ftmodule.h /Users/hiroshi/Downloads/freetype-2.6/include/config/ftoption.h /Users/hiroshi/Downloads/freetype-2.6/include/config/ftstdlib.h  /Users/hiroshi/Downloads/freetype-2.6/objs/ftmodule.h  ; do                         \
          /usr/bin/install -c -m 644                                  \
            $P /usr/local/include/freetype2/config ; \
        done
rm -f /usr/local/include/freetype2/freetype/config/*
rmdir /usr/local/include/freetype2/freetype/config
rmdir: /usr/local/include/freetype2/freetype/config: No such file or directory
make: [install] Error 1 (ignored)
rm -f /usr/local/include/freetype2/freetype/*
rmdir /usr/local/include/freetype2/freetype
rmdir: /usr/local/include/freetype2/freetype: No such file or directory
make: [install] Error 1 (ignored)
/usr/bin/install -c -m 644 ./builds/unix/ftconfig.h               \
          /usr/local/include/freetype2/config/ftconfig.h
/usr/bin/install -c -m 644 /Users/hiroshi/Downloads/freetype-2.6/objs/ftmodule.h                 \
          /usr/local/include/freetype2/config/ftmodule.h
/usr/bin/install -c -m 755 ./builds/unix/freetype-config \
          /usr/local/bin/freetype-config
/usr/bin/install -c -m 644 ./builds/unix/freetype2.m4 \
          /usr/local/share/aclocal/freetype2.m4
/usr/bin/install -c -m 644 ./builds/unix/freetype2.pc \
          /usr/local/lib/pkgconfig/freetype2.pc
/usr/bin/install -c -m 644 /Users/hiroshi/Downloads/freetype-2.6/docs/freetype-config.1 \
          /usr/local/share/man/man1/freetype-config.1

hiroshi-no-MacBook-Air:freetype-2.6 hiroshi$


matplotlibのインストール(zlibのある状態で)

でもって、最後に次のようにコマンドを打ちます。

hiroshi-no-MacBook-Air:freetype-2.6 hiroshi$ pip3 install matplotlib       #  「pip3 install matplotlib」と打ってreturnを押す。

そうすると、次のようになります。

You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already satisfied (use --upgrade to upgrade): matplotlib in /usr/local/lib/python3.4/site-packages
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing!=2.0.0,>=1.5.6 in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six>=1.4 in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pytz in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): nose>=0.11.1 in /usr/local/lib/python3.4/site-packages (from matplotlib)
hiroshi-no-MacBook-Air:freetype-2.6 hiroshi$

以上でとりあえずzlibとfreetype2とmatplotlibのインストールは完了しました。

で、前回と同様に、また次のコードで試してみました。

import networkx as nx

from matplotlib import pyplot

def main() :
 g=nx.Graph()

 g.add_nodes_from(["node","test"])

 g.add_star([1,2,3,4,5])
 g.add_star([6,7,8,9])

 nx.draw(g)

 pyplot.show()

if __name__ == '__main__':
 main()

しかし、結果は前回と変わらず。。。

まあ、いろいろ調べてみたら原因はそこではないようです。

2015年9月4日金曜日

Macでpython3の環境構築5---Matplotlibのインストール2---

さて、前回「Macでpython3の環境構築4---Matplotlibのインストール1」では「zlib→libpng→freetype2→Matplotlib」の順でインストール流れのfreetype2のイントールまでしました(一番最初のzlibは除く)。今回はmatplotlibのインストールをします。

前回に引き続きzlibがない状態でまずは行います。

とはいっても、前回までで下準備はしているので、やることはそんなにありません。

ターミナルを開き、次のようにコマンドを打ちます。


hiroshi-no-MacBook-Air:~ hiroshi$ pip3 install matplotlib    #「pip3 install matplotlib」と打って、returnを押す。


そうすると、以下のような処理がされます。

You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting matplotlib
  Downloading matplotlib-1.4.3-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (47.6MB)
    100% |████████████████████████████████| 47.6MB 9.8kB/s
Collecting nose>=0.11.1 (from matplotlib)
  Downloading nose-1.3.7-py3-none-any.whl (154kB)
    100% |████████████████████████████████| 155kB 1.2MB/s
Collecting pyparsing!=2.0.0,>=1.5.6 (from matplotlib)
  Downloading pyparsing-2.0.3-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in /usr/local/lib/python3.4/site-packages (from matplotlib)
Collecting six>=1.4 (from matplotlib)
  Downloading six-1.9.0-py2.py3-none-any.whl
Collecting pytz (from matplotlib)
  Downloading pytz-2015.4-py2.py3-none-any.whl (475kB)
    100% |████████████████████████████████| 475kB 865kB/s
Collecting python-dateutil (from matplotlib)
  Downloading python_dateutil-2.4.2-py2.py3-none-any.whl (188kB)
    100% |████████████████████████████████| 192kB 1.5MB/s
Installing collected packages: nose, pyparsing, six, pytz, python-dateutil, matplotlib
Successfully installed matplotlib-1.4.3 nose-1.3.7 pyparsing-2.0.3 python-dateutil-2.4.2 pytz-2015.4 six-1.9.0

hiroshi-no-MacBook-Air:~ hiroshi$


試しに、もう一度、
hiroshi-no-MacBook-Air:~ hiroshi$ pip3 install matplotlib    #「pip3 install matplotlib」と打って、returnを押す。

としてみると、
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already satisfied (use --upgrade to upgrade): matplotlib in /usr/local/lib/python3.4/site-packages
Requirement already satisfied (use --upgrade to upgrade): pytz in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing!=2.0.0,>=1.5.6 in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six>=1.4 in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): nose>=0.11.1 in /usr/local/lib/python3.4/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/local/lib/python3.4/site-packages (from matplotlib)
hiroshi-no-MacBook-Air:~ hiroshi$


となり無事インストールされていることがわかります。

ってあれ。zlibがなくてもインストールできたのかしら。

実行する段階でなにかエラーがでるのかと思い、試しにNetworkxのライブラリを使ったプログラムを組み、描画してみました。

『パーフェクトpython』という本を参考にして進めているので、以下のコードで試してみました。

import networkx as nx

from matplotlib import pyplot

def main() :
 g=nx.Graph()

 g.add_nodes_from(["node","test"])

 g.add_star([1,2,3,4,5])
 g.add_star([6,7,8,9])

 nx.draw(g)

 pyplot.show()

if __name__ == '__main__':
 main()

しかし、出てくるのは、

あれ。ラベルがついてない。
もしや、zlibをいれなかったことが原因か。(後ほど調べてみたら、どうやらそうではないらしいですが。)

ということで、今一度zlibをインストールするところまで戻って試してみます。