python
Up one levelrst2pdfでたくさんのテーブルをもったrestructuredtextを変換するとエラー
rst2pdfでテーブルが沢山入ったrestructured text をPDFに変換しようとするとこんなエラーが出た。
File "C:\Python26\lib\site-packages\reportlab\platypus\tables.py", line 205, in spanFixDim t = sum([V[x]+M.get(x,0) for x in xrange(x0,x1)]) TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
検索したらreportlabというソフトのソースを書き換えるという記事が見つかったが、それだけでは治らなかった。
http://comments.gmane.org/gmane.comp.python.reportlab.user/10231
table.pyのspanFixdim() 205行目あたりとお尻の部分を直したら、うまく行くようになった。何をやっているのかはさっぱり分からない。
def spanFixDim(V0,V,spanCons,lim=None,FUZZ=rl_config._FUZZ):
#assign required space to variable rows equally to existing calculated values
M = {}
if not lim: lim = len(V0) #in longtables the row calcs may be truncated
for (x0,x1),v in spanCons.iteritems():
if x0>=lim: continue
x1 += 1
# edited next 6 lines by seko 2012/02/29
#t = sum([V[x]+M.get(x,0) for x in xrange(x0,x1)])
t = 0
for x in xrange(x0, x1):
if V[x] is None:
continue
t += V[x]+M.get(x,0)
if t>=v-FUZZ: continue #already good enough
X = [x for x in xrange(x0,x1) if V0[x] is None] #variable candidates
if not X: continue #something wrong here mate
v -= t
v /= float(len(X))
for x in X:
M[x] = M.get(x,0)+v
# edited next 4 lines by seko
for x,v in M.iteritems():
if V[x] is None:
continue
V[x] += v
- Category(s)
- python
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2846/tbping
Windows7にrst2pdfをインストール
rst2pdf は、restructuredtextで書かれた文書をPDFに変換するソフトでpythonで書かれています。
これまで、 LinuxとMacにインストール してきました。それでもやっぱり、Windowsで動く方が便利だし、多くの人に使ってもらえそうなので試してみます。
こちら を参考に行います。
Python
Python2.6 32bit版 がインストールされています。
rst2opdf 本体をインストールする前に、必要なモジュールやツールをインストールしていきます。
ReportLab Toolkit
http://pypi.python.org/pypi/reportlabからreportlab-2.5.win32-py2.6.exeをダウンロードしてインストール
PIL
http://www.lfd.uci.edu/~gohlke/pythonlibs/からPIL-1.1.7.win32-py2.6.exeをダウンロードして実行。
easy_install
easy-install は、外部ライブラリを簡単にインストールするためのコマンドです。インストールしたいプログラムやライブラリを、コマンドを一つ入力するだけで、実行するのに必要なものも一緒にダウンロードしてくれます。
http://peak.telecommunity.com/dist/ez_setup.py 上記のリンクを右クリックして保存します。テキストファイルが見えてしまったら、右クリックで保存してください。
ダウンロードしたら、DOS Box開いて、ファイルのあるところまで移動してから、以下のように実行します。インターネット環境にproxy経由で接続している場合は、IEのproxy設定がdosboxでも有効な気がします。proxyが認証を要求するタイプだとうまくいかないかもしれません。proxyがあると複雑になりますね。試行錯誤でやっているので、うまくいくとき行かないときの違いが分からないことが多いです。
C:\Python26\python ez_setup.py
Pygments
easy_installを使ってインストールします。どうしてイントーラタイプはないのでしょうか?
C:Python26Scripts>easy_install.exe Pygments
docutils
easy_installを使ってインストールします。これもインストーラタイプは無いようです。
C:Python26Scripts>easy_install.exe docutils
rst2pdf 本体のインストール
http://code.google.com/p/pythonxy/downloads/list から rst2pdf-0.16_py26.exe をダウンロード。デフォルトではpythonの最新バージョン2.7用しか表示されていないので rst2pdfと検索してpython2.6用を探すこと。
実行してみると次のようなエラーが出ました。
C:\Python26\Scripts>rst2pdf.exe test.rst
Traceback (most recent call last):
File "C:\Python26\Scripts\rst2pdf-script.py", line 8, in <module>
load_entry_point('rst2pdf==0.16', 'console_scripts', 'rst2pdf')()
File "C:\Python26\lib\site-packages\rst2pdf\createpdf.py", line 1452, in main
numbered_links=options.numbered_links,
File "C:\Python26\lib\site-packages\rst2pdf\createpdf.py", line 169, in __ini
__
get_language (self.language)
TypeError: get_language() takes exactly 2 arguments (1 given)
C:Python26Libsite-packagesdocutils-0.8.1-py2.6.eggdocutilslanguages__init__.pyをエディタで開いて、次のように書き換えます。
def get_language(language_code, reporter): ↓ def get_language(language_code, reporter=None):
もう一度起動してみて、PDFが作られればOKです。
- Category(s)
- python
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2841/tbping
pythonで行列を転置する
リストではなくて、arrayにしたら簡単に転置できました。
In [31]: import numpy as np
In [32]: a=np.array([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]])
In [33]: a
Out[33]:
array([[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5]])
In [34]: a.transpose()
Out[34]:
array([[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5]])
- Category(s)
- python
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2835/tbping
リストを転置するpythonスクリプト
リストで作った行列の縦横を入れ替えます。
def invert_lst(lst):
col = len(lst[0])
row = len(lst)
inv = []
for i in range(col):
l = []
for j in range(row):
l.append('')
inv.append(l)
for i in range(row):
for j in range(col):
inv[j][i] = lst[i][j]
return inv
lst = [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
print invert_lst(lst)
>>>[[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3]]
- Category(s)
- python
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2830/tbping
Windows7にpython,numpy,matplotlib,IPythonをインストール
インストール先は、Windows7 64bit版
Python
Python標準リリース からWindows用インストーラ python-2.6.6.msi をダウンロードして実行。OSが64ビットであっても、pythonは32ビット版を用いること。64ビット版だと、以降のモジュールのインストーラが認識できない。
numpy
Scientific Computing Tools For Python — Numpy から たどっていって numpy-1.6.1-win32-superpack-python2.6.exe をダウンロードしてインストール
scipy
SciPy - から scipy-0.10.0-win32-superpack-python2.6.exe をダウンロードしてインストール。
matplotlib
http://sourceforge.net/projects/matplotlib/files/ から、 matplotlib-1.1.0.win32-py2.6.exe をダンロードしてインストール。
IPython
http://ipython.org/download.html から ipython-0.12.win32-setup.exe をダウンロードしてインストール
起動すると ImportError: No module named pkg_resources というエラーがでる。
setuptoolsがいるとのことで、
http://pypi.python.org/pypi/setuptools から http://pypi.python.org/pypi/setuptools#files にいって、 setuptools-0.6c11.win32-py2.6.exe (md5) をインストール
起動すると、まだ次のようなエラーが出る。
C:\Python26\Scripts>ipython.exe WARNING: Readline services not available or not loaded.WARNING: Proper color sup port under MS Windows requires the pyreadline library. You can find it at: http://ipython.org/pyreadline.html Gary's readline needs the ctypes module, from: http://starship.python.net/crew/theller/ctypes (Note that ctypes is already part of Python versions 2.5 and newer). Defaulting color scheme to 'NoColor'Python 2.6.6 (r266:84297, Aug 24 2010, 18:46 :32) [MSC v.1500 32 bit (Intel)] Type "copyright", "credits" or "license" for more information. IPython 0.12 -- 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.
readlineというのがいるらしいので、
https://launchpad.net/pyreadline/+download から pyreadline-1.7.1.win32.exe をダウンロード
これでOK
Windowsの環境設定
Pythonのpathを通すために環境変数に C:¥Python26¥;C:¥Python26¥Script¥; を追加する。最後の¥を入れないとなぜかpathが通らなかった。
- Category(s)
- python
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2823/tbping
PythonでExcelファイルを読む
今回は、 xlrd というモジュールを使ってみました。 Python-izm そのままです。
インタラクティブシェルの IPython を初めて使ってみました。
In [3]: import xlrd
In [4]: book = xlrd.open_workbook('fruitslst.xls')
In [5]: print book.nsheets
3
In [6]: for name in book.sheet_names():
...: print name
...:
Sheet1
Sheet2
Sheet3
In [7]: print book.sheet_by_index(0).name
Sheet1
In [9]: print book.sheet_by_name('Sheet2').name
Sheet2
In [10]: sheet_1 = book.sheet_by_index(0)
In [11]: for col in range(sheet_1.ncols):
....: print '-' * 20
....: for row in range(sheet_1.nrows):
....: print sheet_1.cell(row,col).value
....:
--------------------
Apple
Orenge
Melon
--------------------
3.0
2.0
1.0
- Category(s)
- python
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2818/tbping
Macbook AirにHomebrew,matplotlibをインストール失敗→成功!
Macbook Airのpythonでグラフが描きたいです。
1.Homebrewをインストールする
kazhr さんのところに書いてあることをそのまま実行
開発環境XcodeをApp storeで購入しておく
$ ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"
と実行
seko$ ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)" ==> This script will install: /usr/local/bin/brew /usr/local/Library/Formula/... /usr/local/Library/Homebrew/... ==> The following directories will be made group writable: /usr/local/. ==> The following directories will have their group set to admin: /usr/local/.Press enter to continue ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. Password: ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/. ==> Downloading and Installing Homebrew... ==> Installation successful! Now type: brew help
アップデート
seko$ brew update Initialized empty Git repository in /usr/local/.git/ remote: Counting objects: 53169, done. remote: Compressing objects: 100% (24377/24377), done. remote: Total 53169 (delta 34111), reused 44744 (delta 28086) Receiving objects: 100% (53169/53169), 7.69 MiB | 1.10 MiB/s, done. Resolving deltas: 100% (34111/34111), done. From https://github.com/mxcl/homebrew [new branch] gh-pages -> origin/gh-pages [new branch] master -> origin/master HEAD is now at f78eb1c wireshark: add 1.7.0 as the devel version Already up-to-date.
2. PILをインストール
こちら に書いてある通りに実行。
seko$ sudo easy_install pip seko$ sudo ARCHFLAGS="-arch i386 -arch x86_64" pip install PIL
3.ScipySuperpackをインストール
https://github.com/fonnesbeck/ScipySuperpack
にいって、下の方にあるDownload Scipy Superpack Installer for OSX 10.7 を保存。
ちなみに2012年1月31日の依存性は
Dependencies OS X 10.7 (Lion), Python 2.7, Xcode 4.2
ダウンロードしたディレクトリで
$ sh install_superpack.sh
と実行するとNumpy (2.0) and Scipy (0.11), Matplotlib (1.2), iPython (0.12), Pandas (0.6)がまとめてインストールされるらしい。
$ sh install_superpack.sh
Are you installing from a repository cloned to this machine (if unsure, answer no)? (y/n)
y
Downloading gFortran ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 11.3M 100 11.3M 0 0 352k 0 0:00:32 0:00:32 --:--:-- 127k
Installing gFortran ...
Password:
installer: Package name is GNU Fortran 4.2.4 for Lion Xcode 4.1 (build 5666.3)
installer: Installing at base path /
installer: The install was successful.
Installing Scipy Superpack ...
error: Not a URL, existing file, or requirement spec: ./*.egg
Installing readline ...
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Reading http://github.com/ludwigschwardt/python-readline
Best match: readline 6.2.1
Downloading http://pypi.python.org/packages/2.7/r/readline/readline-6.2.1-py2.7-macosx-10.7-intel.egg#md5=8aef7cc656e1bdfe851a8e6f91c63c4c
Processing readline-6.2.1-py2.7-macosx-10.7-intel.egg
creating /Library/Python/2.7/site-packages/readline-6.2.1-py2.7-macosx-10.7-intel.egg
Extracting readline-6.2.1-py2.7-macosx-10.7-intel.egg to /Library/Python/2.7/site-packages
Adding readline 6.2.1 to easy-install.pth file
Installed /Library/Python/2.7/site-packages/readline-6.2.1-py2.7-macosx-10.7-intel.egg
Installing nose ...
Searching for nose
Reading http://pypi.python.org/simple/nose/
Reading http://somethingaboutorange.com/mrl/projects/nose/
Reading http://readthedocs.org/docs/nose/
Best match: nose 1.1.2
Downloading http://pypi.python.org/packages/source/n/nose/nose-1.1.2.tar.gz#md5=144f237b615e23f21f6a50b2183aa817
Processing nose-1.1.2.tar.gz
Running nose-1.1.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-3XrNEO/nose-1.1.2/egg-dist-tmp-uR71QE
Adding nose 1.1.2 to easy-install.pth file
Installing nosetests script to /usr/local/bin
Installing nosetests-2.7 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg
Installing DateUtils
Searching for DateUtils
Reading http://pypi.python.org/simple/DateUtils/
Best match: DateUtils 0.5.1
Downloading http://pypi.python.org/packages/source/D/DateUtils/DateUtils-0.5.1.tar.gz#md5=40cff15a40664eeb117361049edbd0bd
Processing DateUtils-0.5.1.tar.gz
Running DateUtils-0.5.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-QrU1Rh/DateUtils-0.5.1/egg-dist-tmp-a7rRdp
zip_safe flag not set; analyzing archive contents...
Adding DateUtils 0.5.1 to easy-install.pth file
Installed /Library/Python/2.7/site-packages/DateUtils-0.5.1-py2.7.egg
Done
pythonでインポートしてみると。。。だめです。
$ python Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib Traceback (most recent call last): File "", line 1, in ImportError: No module named matplotlib
調べてみるとマシンのXcodeのバージョンは4.1です。要求されているバージョンは4.2なので、App Storeを見に行くと4.2がダウンロード済みになっていて、更新することができません。検索してみると、同じ現象 を見つけました。 「アプリケーション」フォルダーに保存されていたの"Install Xcode" を実行して無事4.2になりました。 この後、再びScipySuperpackを実行したら、matplotlibが使えるようになりました。
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2807/tbping
CentOS6.2にmatplotlibをインストール
[root@localhost ~]# yum search matplotlib Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile base: rsync.atworks.co.jp extras: rsync.atworks.co.jp * updates: rsync.atworks.co.jp =========================== N/S Matched: matplotlib ============================ python-matplotlib-tk.x86_64 : Tk backend for python-matplotlib python-matplotlib.x86_64 : Python plotting library
Name and summary matches only, use "search all" for everything. [root@localhost ~]# yum install python-matplotlib Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile base: rsync.atworks.co.jp extras: rsync.atworks.co.jp * updates: rsync.atworks.co.jp Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package python-matplotlib.x86_64 0:0.99.1.2-1.el6 will be installed --> Processing Dependency: python-dateutil for package: python-matplotlib-0.99.1.2-1.el6.x86_64 --> Processing Dependency: pytz for package: python-matplotlib-0.99.1.2-1.el6.x86_64 --> Processing Dependency: numpy for package: python-matplotlib-0.99.1.2-1.el6.x86_64 --> Running transaction check ---> Package numpy.x86_64 0:1.3.0-6.2.el6 will be installed --> Processing Dependency: python-nose for package: numpy-1.3.0-6.2.el6.x86_64 --> Processing Dependency: libptf77blas.so.3()(64bit) for package: numpy-1.3.0-6.2.el6.x86_64 --> Processing Dependency: libatlas.so.3()(64bit) for package: numpy-1.3.0-6.2.el6.x86_64 --> Processing Dependency: liblapack.so.3()(64bit) for package: numpy-1.3.0-6.2.el6.x86_64 --> Processing Dependency: libptcblas.so.3()(64bit) for package: numpy-1.3.0-6.2.el6.x86_64 ---> Package python-dateutil.noarch 0:1.4.1-6.el6 will be installed ---> Package pytz.noarch 0:2010h-2.el6 will be installed --> Running transaction check ---> Package atlas.x86_64 0:3.8.4-1.el6 will be installed ---> Package python-nose.noarch 0:0.10.4-3.1.el6 will be installed --> Processing Dependency: python-setuptools for package: python-nose-0.10.4-3.1.el6.noarch --> Running transaction check ---> Package python-setuptools.noarch 0:0.6.10-3.el6 will be installed --> Finished Dependency Resolution
Dependencies Resolved
================================================================================ Package Arch Version Repository Size ================================================================================ Installing: python-matplotlib x86_64 0.99.1.2-1.el6 base 3.2 M Installing for dependencies: atlas x86_64 3.8.4-1.el6 base 2.8 M numpy x86_64 1.3.0-6.2.el6 base 1.6 M python-dateutil noarch 1.4.1-6.el6 base 84 k python-nose noarch 0.10.4-3.1.el6 base 220 k python-setuptools noarch 0.6.10-3.el6 base 336 k pytz noarch 2010h-2.el6 base 35 k
Transaction Summary ================================================================================ Install 7 Package(s)
Total download size: 8.4 M Installed size: 33 M Is this ok [y/N]: y Downloading Packages: (1/7): atlas-3.8.4-1.el6.x86_64.rpm | 2.8 MB 00:00 (2/7): numpy-1.3.0-6.2.el6.x86_64.rpm | 1.6 MB 00:00 (3/7): python-dateutil-1.4.1-6.el6.noarch.rpm | 84 kB 00:00 (4/7): python-matplotlib-0.99.1.2-1.el6.x86_64.rpm | 3.2 MB 00:00 (5/7): python-nose-0.10.4-3.1.el6.noarch.rpm | 220 kB 00:00 (6/7): python-setuptools-0.6.10-3.el6.noarch.rpm | 336 kB 00:00 (7/7): pytz-2010h-2.el6.noarch.rpm | 35 kB 00:00 -------------------------------------------------------------------------------- Total 3.2 MB/s | 8.4 MB 00:02 警告: rpmts_HdrFromFdno: ヘッダ V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 Importing GPG key 0xC105B9DE: Userid : CentOS-6 Key (CentOS 6 Official Signing Key)
Package: centos-release-6-2.el6.centos.7.x86_64 (@anaconda-CentOS-201112091719.x86_64/6.2) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 Is this ok [y/N]: y Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : atlas-3.8.4-1.el6.x86_64 1/7 Installing : python-setuptools-0.6.10-3.el6.noarch 2/7 Installing : python-nose-0.10.4-3.1.el6.noarch 3/7 Installing : numpy-1.3.0-6.2.el6.x86_64 4/7 Installing : python-dateutil-1.4.1-6.el6.noarch 5/7 Installing : pytz-2010h-2.el6.noarch 6/7 Installing : python-matplotlib-0.99.1.2-1.el6.x86_64 7/7 Installed: python-matplotlib.x86_64 0:0.99.1.2-1.el6
Dependency Installed: atlas.x86_64 0:3.8.4-1.el6 numpy.x86_64 0:1.3.0-6.2.el6 python-dateutil.noarch 0:1.4.1-6.el6 python-nose.noarch 0:0.10.4-3.1.el6 python-setuptools.noarch 0:0.6.10-3.el6 pytz.noarch 0:2010h-2.el6
Complete! [root@localhost ~]#
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2806/tbping
Macbook airにrst2pdfインストール 失敗
開発環境のX codeを入れればいいのかな?
Last login: Sun Jan 1 21:55:24 on console seiinishiekuchi-haku-no-MacBook-Air:~ seko$ sudo easy_install rst2pdfWARNING: Improper use of the sudo command could lead to data loss or the deletion of important system files. Please double-check your typing when using sudo. Type "man sudo" for more information.
To proceed, enter your password, or type Ctrl-C to abort.
Password: Searching for rst2pdf Reading http://pypi.python.org/simple/rst2pdf/ Reading http://rst2pdf.googlecode.com Reading http://code.google.com/p/rst2pdf/downloads/list Best match: rst2pdf 0.16 Downloading http://rst2pdf.googlecode.com/files/rst2pdf-0.16.tar.gz Processing rst2pdf-0.16.tar.gz Running rst2pdf-0.16/setup.py -q bdist_egg --dist-dir /tmp/easy_install-BL1bhd/rst2pdf-0.16/egg-dist-tmp-aVQigh zip_safe flag not set; analyzing archive contents... rst2pdf.createpdf: module references __file__ rst2pdf.image: module references __file__ rst2pdf.pdfbuilder: module references __file__ rst2pdf.styles: module references __file__ rst2pdf.tests.autotest: module references __file__ rst2pdf.tests.execmgr: module references __file__ Adding rst2pdf 0.16 to easy-install.pth file Installing rst2pdf script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/rst2pdf-0.16-py2.7.egg Processing dependencies for rst2pdf Searching for Pygments Reading http://pypi.python.org/simple/Pygments/ Reading http://pygments.org/ Reading http://pygments.pocoo.org/ Best match: Pygments 1.4 Downloading http://pypi.python.org/packages/2.7/P/Pygments/Pygments-1.4-py2.7.egg#md5=acbdde4dae30efaba8cfa86dcb6070f2 Processing Pygments-1.4-py2.7.egg creating /Library/Python/2.7/site-packages/Pygments-1.4-py2.7.egg Extracting Pygments-1.4-py2.7.egg to /Library/Python/2.7/site-packages Adding Pygments 1.4 to easy-install.pth file Installing pygmentize script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/Pygments-1.4-py2.7.egg Searching for reportlab>=2.1 Reading http://pypi.python.org/simple/reportlab/ Reading http://www.reportlab.com/ Best match: reportlab 2.5 Downloading http://pypi.python.org/packages/source/r/reportlab/reportlab-2.5.tar.gz#md5=cdf8b87a6cf1501de1b0a8d341a217d3 Processing reportlab-2.5.tar.gz Running reportlab-2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-qhYqVC/reportlab-2.5/egg-dist-tmp-1kvi8h ################################################ #Attempting install of _rl_accel, sgmlop & pyHnj #extensions from
/private/tmp/easy_install-qhYqVC/reportlab-2.5/src/rl_addons/rl_accel################################################ ################################################ #Attempting install of _renderPM #extensions from/private/tmp/easy_install-qhYqVC/reportlab-2.5/src/rl_addons/renderPM# installing without freetype no ttf, sorry! # You need to install a static library version of the freetype2 software # If you need truetype support in renderPM # You may need to edit setup.cfg (win32) # or edit this file to access the library if it is installed ################################################ Downloading standard T1 font curves Finished download of standard T1 font curves unable to execute llvm-gcc-4.2: No such file or directory error: Setup script exited with error: commandllvm-gcc-4.2failed with exit status 1 seiinishiekuchi-haku-no-MacBook-Air:~ seko$
なんとかインストールしても実行するとエラーになります。
$ rst2pdf sample.rst Traceback (most recent call last): File "/usr/local/bin/rst2pdf", line 8, inload_entry_point( rst2pdf==0.16,console_scripts,rst2pdf)() File "/Library/Python/2.7/site-packages/rst2pdf-0.16-py2.7.egg/rst2pdf/createpdf.py", line 1452, in main numbered_links=options.numbered_links, File "/Library/Python/2.7/site-packages/rst2pdf-0.16-py2.7.egg/rst2pdf/createpdf.py", line 169, in __init__ get_language (self.language) TypeError: get_language() takes exactly 2 arguments (1 given) seiinishiekuchi-no-MacBook-Air:Desktop seko$
こちら を参考に、エラーメッセージを見てパスを探して__init__.pyを書き換えます。
$ sudo vim /Library/Python/2.7/site-packages/docutils-0.8.1-py2.7.egg/docutils/languages/__init__.py
def get_language(language_code, reporter): ↓ def get_language(language_code, reporter=None):
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2796/tbping
Linuxへのrst2pdfインストールとエラー回避
pythonを使ってデータを処理し、PDFでレポートを作りたいと思います。
調べてみるとpythonで書かれたrst2pdf を使うと、reStructuredtextをpdfに変換できるようです。
OSは、Scientific Linux6.1 です。CentOS6.1でも同じはずです。
インストール
easy_install というのを使う為にpython-setuptoolsを入れます。また、python-develが入っていないとrst2pdfをインストールしたときにエラーがでました。
# yum install python-setuptools # yum install python-devel # yum install python-imaging # easy_install rst2pdf
実行時のエラー
rst2pdf sample.rst
とするとエラーになります。
TypeError:get_language()takesexactly2arguments (1 given)
こちら を参考に、エラーメッセージを見てパスを探して site-packages/docutils/languages/__init__.pyのdef get_languageを書き換えます。
def get_language(language_code, reporter): ↓ def get_language(language_code, reporter=None):
- Category(s)
- python
- The URL to Trackback this entry is:
- http://lightson.dip.jp/blog/seko/2795/tbping