To content | To menu | To search

Tag - Python

Entries feed - Comments feed

Thursday, February 2 2017

FreeBSD と Python3 で Jupyter notebook を動かした話

pkg や ports で Python3 をインストールしようとしても、周りのライブラリなどが複数のバージョンの Python2 をインストールしようとするので、観念して pkg や ports を使わずにセットアップした話。

Continue reading...

Sunday, January 17 2016

ドキュメンテーションツール 2016 (2)

引き続き Sphinx を試しているところ。

見出しというか、章や節の深さについては、reStructuredText入門 の「セクション」を見て解決。今回の対象のテキストはこのくらいの深さでカバーできた。

ソースコードや脚注、欄外の注釈なども順調に対処。

画像については Sphinxで出力フォーマットごとに記述を変更する でまずは latex とそれ以外を分離。LaTeX 以外には png を指定。

画像は元々 Visio で書いていたので、画像は png と wmf を出力していた。wmf を LaTeX 向けの EPS に変換するのは、WMF2EPS の開発が終了してしまったので、去年つかった LyX と一緒に配布されている MetafileToEPSConverter を使用。

ただ、最初は dvipdfmx が、EPS ファイルが見つからないとエラーになっていた。epspdf で問題の EPS ファイルを変換させようとしてみたら GhostScript が無い、というエラーだったので GhostScript (9-base) をインストールすることで解決。

ただこの Metafile To EPS Converter の結果が、フォントが違ってしまうので、TeX Live の日本語フォントも含めてチェックが必要そう。

でもとりあえず、おそらくこれで材料はそろったので、あとは PDF にしたときのスタイルや、HTML のスタイルや、EPUB のスタイルを考えるくらいか。

Monday, January 11 2016

ドキュメンテーションツール 2016 (1)

今年はまずは、Sphinx + LaTeX に挑戦。

Sphinx で sphinx-quickstart で作った Makefile がいきなりエラーで焦ったけれど、if うんぬんから endif までの3行をコメントアウトすることで回避。
(もともとコマンドがインストールされているかのチェックだけみたいだから)

ただ make で PDF を出力させようとしているのに tex 出力だけで何も言わずに終わってしまう。
日本語周りの例外の処理でエラーになってる模様。

どう対応していいかよくわからないので、Python 3 最新版をパッケージでインストールした後 Sphinx を pip でインストール。
TeX Live もオリジナルのサイトからインストーラーをダウンロードしてインストール。

パッケージ管理としては面倒になるけれど、これで Makefile の内容も少し変わったし、PDF 出力もされた。

内容に関しては、章や節の深さが、Sphinx のマークダウンだけだと浅いけれど、toc 周りを活用してファイル分割すればいけるらしい。
画像に関してのみ、EPS なりなんなり、ベクター形式でいければ、あとはスタイルをどういじるか……で済むと期待。

Thursday, June 18 2015

IPython Notebook

面白そうだったのでセットアップしてみた。

FreeBSD なら

# pkg install devel/ipython

で一発。
ローカルで動かすなら

$ ipython notebook

でいいけれど、サーバーで動かしたいとき。

# ipython notebook --no-browser --port=80 --ip=xxx.xxx.xxx.xxx

ポート 80 はルート権限でないと使わせてくれない?あと Listen するアドレスの指定が必要だった。
さすがにこのまま外には公開できないのでもう少しセットアップ。

必要なことは全て

$ ipython help notebook --help-all

ここから。

とりあえず TLS 対応してみたい。ひとまず勝手証明書で。ディレクトリは適当。

# mkdir /usr/local/etc/cert
# cd /usr/local/etc/cert/
root@freebsd:/usr/local/etc/cert # openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
......++++++
...........................................................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
root@freebsd:/usr/local/etc/cert # openssl req -new -days 365 -key server.key -out server.csr
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]: **
State or Province Name (full name) [Some-State]: *****
Locality Name (eg, city) []:*****
Organization Name (eg, company) [Internet Widgits Pty Ltd]:*****
Organizational Unit Name (eg, section) []:*****
Common Name (e.g. server FQDN or YOUR name) []:*****.example.jp
Email Address []:*****@example.jp

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
root@freebsd:/usr/local/etc/cert #
root@freebsd:/usr/local/etc/cert # openssl x509 -req -signkey server.key -days 365 -in server.csr -out server.crt
Signature ok
subject=/C=**/ST=*****/L=*****/O=*****/OU=*****/CN=*****.example.jp/emailAddress=*****@example.jp
Getting Private key
Enter pass phrase for server.key:
root@freebsd:/usr/local/etc/cert # mv server.key server.key.bak
root@freebsd:/usr/local/etc/cert # openssl rsa -in server.key.bak -out server.key
Enter pass phrase for server.key.bak:
writing RSA key
root@freebsd:/usr/local/etc/cert # ls
server.crt      server.csr      server.key      server.key.bak

(この鍵の作り方は古いかもしれない)
として関連ファイルを作ったあとで、

# ipython notebook --no-browser --port=443 --ip=***.example.jp --NotebookApp.certfile=/usr/local/etc/cert/server.crt --NotebookApp.keyfile=/usr/local/etc/cert/server.key

とすると https://***.example.jp/ で TLS 接続。

IPython のためのディレクトリも作っておこう。

# mkdir /home/ipython
# mkdir /home/ipython/.ipython
# mkdir /home/ipython/notebook

あとは、開きっぱなしっていうのもいやなので、パスワードを設定したい。

$ ipython
Python 2.7.9 (default, Jun 12 2015, 19:23:08)
Type "copyright", "credits" or "license" for more information.

IPython 3.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from IPython.lib import passwd; passwd()
Enter password:
Verify password:
Out[1]: 'sha1:****************************************************************'

In [2]: exit

というわけで全部設定。ロギングも入れた。

# ipython notebook --no-browser --port=443 --ip=*****.example.jp --NotebookApp.certfile=/usr/local/etc/cert/server.crt --NotebookApp.keyfile=/usr/local/etc/cert/server.key --NotebookApp.password='sha1:****************************************************************' --ipython-dir=/home/ipython/.ipython --notebook-dir=/home/ipython/notebook --log-level=WARN

ログインのときユーザー名は無いので、共用には向かないみたい。

あとこのままではルート権限で動いているので、起動しっぱなし、というのは怖い。