addpage を使いたかったのでUbuntu16.04にインストールしようとしたらエラーが出ました。
(今回、管理者権限が必要なところは sudo bash でrootユーザになって実行しています。)
# pip3 install addpage
The directory '/home/nanbuwks/.cache/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.
The directory '/home/nanbuwks/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting addpage
Downloading https://files.pythonhosted.org/packages/ec/d0/1b1b5b51d6d7fb92bbda897bab4f3218776f6ebec5adc79c89af8390e287/addpage-0.0.2.tar.gz
Collecting PyPDF2 (from addpage)
Downloading https://files.pythonhosted.org/packages/b4/01/68fcc0d43daf4c6bdbc6b33cc3f77bda531c86b174cac56ef0ffdb96faab/PyPDF2-1.26.0.tar.gz (77kB)
100% |████████████████████████████████| 81kB 449kB/s
Requirement already satisfied (use --upgrade to upgrade): reportlab in /usr/lib/python3/dist-packages (from addpage)
Collecting pdfformfiller (from addpage)
Downloading https://files.pythonhosted.org/packages/5c/6d/3a2f5d9d0f65130075c778d0f88e6cfdeef432fe864f2c1fb41423279dc5/PdfFormFiller-0.4.tar.gz
Installing collected packages: PyPDF2, pdfformfiller, addpage
Running setup.py install for PyPDF2 ... done
Running setup.py install for pdfformfiller ... done
Running setup.py install for addpage ... done
Successfully installed PyPDF2-1.26.0 addpage-0.0.2 pdfformfiller-0.4
You are using pip version 8.1.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@LATITUDE:~/storage/openforce/dozinsi/DE-PiAll# addpage -h
Traceback (most recent call last):
File "/usr/local/bin/addpage", line 9, in <module>
load_entry_point('addpage==0.0.2', 'console_scripts', 'addpage')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 542, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2569, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2229, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python3.5/dist-packages/addpage.py", line 33
print(f'Not found {inFile}', file=sys.stderr)
^
SyntaxError: invalid syntax
実行してもエラーが出ます。
# addpage --h
Traceback (most recent call last):
File "/usr/local/bin/addpage", line 9, in <module>
load_entry_point('addpage==0.0.2', 'console_scripts', 'addpage')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 542, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2569, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2229, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python3.5/dist-packages/addpage.py", line 33
print(f'Not found {inFile}', file=sys.stderr)
^
SyntaxError: invalid syntax
pythonバージョンが3.5.2だからぽいです。
# python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
Python3.6をインストール
https://qiita.com/Fendo181/items/912b65c4fcc3d701d53d
に基づき、Python3.6をインストールします
Pyenv を使えるようにする
# apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libbz2-dev libreadline-dev
# git clone https://github.com/yyuu/pyenv.git ~/.pyenv
# echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
# echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
# echo 'eval "$(pyenv init -)"' >> ~/.profile
# source ~/.profile
Pyenv から Python3.6.0をインストール
# pyenv install 3.6.0
Downloading Python-3.6.0.tar.xz...
-> https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
Installing Python-3.6.0...
Installed Python-3.6.0 to /home/nanbuwks/.pyenv/versions/3.6.0
インストールできたので、pythonを起動したときに3.6.0が動くようにする。
# pyenv global 3.6.0
としたが、これは結果的に誤りだった。常に3.6.0が起動するようになり、既存のバージョンのPythonが必要なプログラムで支障が出るようになった。
今回はaddpageを使うためだけに必要なので、
# pyenv shell 3.6.0
などとやった方が良かったみたい。
global で設定した解除方法は後述。
addpage を pipでインストールする
# pip -V
pip 9.0.1 from /home/nanbuwks/.pyenv/versions/3.6.0/lib/python3.6/site-packages (python 3.6)
いけそうですね。
# pip install addpage
The directory '/home/nanbuwks/.cache/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.
The directory '/home/nanbuwks/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting addpage
Downloading https://files.pythonhosted.org/packages/ec/d0/1b1b5b51d6d7fb92bbda897bab4f3218776f6ebec5adc79c89af8390e287/addpage-0.0.2.tar.gz
Collecting PyPDF2 (from addpage)
Downloading https://files.pythonhosted.org/packages/b4/01/68fcc0d43daf4c6bdbc6b33cc3f77bda531c86b174cac56ef0ffdb96faab/PyPDF2-1.26.0.tar.gz (77kB)
100% |████████████████████████████████| 81kB 575kB/s
Collecting reportlab (from addpage)
Downloading https://files.pythonhosted.org/packages/b9/13/caf6e87cb74c4a1e5642c55d90a205e0186ad123f3fb093e91711097c8f0/reportlab-3.5.9-cp36-cp36m-manylinux1_x86_64.whl (2.6MB)
100% |████████████████████████████████| 2.6MB 441kB/s
Collecting pdfformfiller (from addpage)
Downloading https://files.pythonhosted.org/packages/5c/6d/3a2f5d9d0f65130075c778d0f88e6cfdeef432fe864f2c1fb41423279dc5/PdfFormFiller-0.4.tar.gz
Collecting pillow>=4.0.0 (from reportlab->addpage)
Downloading https://files.pythonhosted.org/packages/62/94/5430ebaa83f91cc7a9f687ff5238e26164a779cca2ef9903232268b0a318/Pillow-5.3.0-cp36-cp36m-manylinux1_x86_64.whl (2.0MB)
100% |████████████████████████████████| 2.0MB 588kB/s
Installing collected packages: PyPDF2, pillow, reportlab, pdfformfiller, addpage
Running setup.py install for PyPDF2 ... done
Running setup.py install for pdfformfiller ... done
Running setup.py install for addpage ... done
Successfully installed PyPDF2-1.26.0 addpage-0.0.2 pdfformfiller-0.4 pillow-5.3.0 reportlab-3.5.9
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# addpage -h
usage: addpage [-h] [-o OUTFILE] [-n FONT_NAME] [-z FONT_SIZE] [-s START]
[-k SKIP] [-x MARGIN_X] [-y MARGIN_Y] [-a {center,left,right}]
[-f FORMAT]
infile
Add page number to PDF file.
positional arguments:
infile input PDF file
optional arguments:
-h, --help show this help message and exit
-o OUTFILE, --outfile OUTFILE
-n FONT_NAME, --font-name FONT_NAME
-z FONT_SIZE, --font-size FONT_SIZE
-s START, --start START
-k SKIP, --skip SKIP
-x MARGIN_X, --margin-x MARGIN_X
-y MARGIN_Y, --margin-y MARGIN_Y
-a {center,left,right}, --alignment {center,left,right}
-f FORMAT, --format FORMAT
rootユーザーで使えるようになりました
一般ユーザの設定
一般ユーザーでの pyenv の修復
一般ユーザでも、pyenv global を使いました。
(これについても、後で間違いとわかった。 pyenv shell 3.6.0 などとする必要がある)
$ pyenv global 3.6.0
コマンド 'pyenv' は見つかりませんでした。もしかして:
コマンド 'pyvenv' - パッケージ 'python3-venv' (universe)
コマンド 'p7env' - パッケージ 'libnss3-tools' (universe)
pyenv: コマンドが見つかりません
sudo bash で作ったroot上でpyenvの設定をしたのが原因です。
$ ls -alh ~/.pyenv
とすると root:root だったので、
$ sudo chown -R nanbuwks:nanbuwks ~/.pyenv
$ pyenv global 3.6.0
で通りました。addpageもOKでした。
間違って pyenv global した設定を解除する
pyenv で設定したのを忘れて Arduino 開発環境を動かそうとしたら書き込みできませんでした。あれれー??と思っていたら Python のバージョンの問題でした。
エラーの内容
・・・
Arduino Version: 1.6.9
Traceback (most recent call last):
File "/home/nanbuwks/Arduino/hardware/espressif/esp32/tools/esptool.py", line 25, in <module>
import serial
ModuleNotFoundError: No module named 'serial'
exit status 1
ボードWEMOS LOLIN32に対するコンパイル時にエラーが発生しました。
復旧方法です。
$ python -V
Python 3.6.0
$ cat ~/.pyenv/version
Python 3.6.0
で今設定しているバージョンを確認
$ rm ~/.pyenv/version
$ source ~/.profile
$ python -V
Python 2.7.12
この後、Arduino開発環境を実行すると直りました。