動かざることバグの如し

近づきたいよ 君の理想に

Python(Anaconda)でCythonのインストールにコケる件

環境

症状

pip install cythonでエラーになる

  Found existing installation: bleach 2.0.0
    Uninstalling bleach-2.0.0:
      Successfully uninstalled bleach-2.0.0
  Found existing installation: Cython 0.26.1
    Uninstalling Cython-0.26.1:
Exception:
Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/shutil.py", line 544, in move
    os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/anaconda3/lib/python3.6/site-packages/__pycache__/cython.cpython-36.pyc' -> '/var/folders/6z/xq_8ddx97hq9hzlgwzjjdjbw0000gn/T/pip-zvhgvr6a-uninstall/anaconda3/lib/python3.6/site-packages/__pycache__/cython.cpython-36.pyc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/anaconda3/lib/python3.6/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/anaconda3/lib/python3.6/site-packages/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/anaconda3/lib/python3.6/site-packages/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/anaconda3/lib/python3.6/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/anaconda3/lib/python3.6/site-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/anaconda3/lib/python3.6/shutil.py", line 558, in move
    copy_function(src, real_dst)
  File "/anaconda3/lib/python3.6/shutil.py", line 257, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/anaconda3/lib/python3.6/shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/anaconda3/lib/python3.6/site-packages/__pycache__/cython.cpython-36.pyc'

とりあえず以下のコマンドを実行

conda install -c anaconda cython

その後に再度pip installするといける。

同じAnacondaでやってるはずなのに上手くいくときもある。なぜだか理由がわからない。。。。

Ubuntuで古いバージョンのパッケージをインストールする

環境

最新ではなく1つ前のバージョンをインストールしたい、ってのはよくあると思う。そもそも特定のバージョンをインストールするには、そのバージョンがいくつかを知る必要があるのだが、Ubuntuだと結構面倒だった。

古い記事(Ubuntu 12とか)だとapt-show-versionsコマンド使おうとか、apt-cacheで裏技的にバージョンを表示していたが、aptコマンドに統一されてからは結構直感的に出来るようになった わーい

方法

例えば cudaのバージョン一覧を表示したい場合、apt show <パッケージ名> -aで一覧が表示される。-aをつけないと最新版歯科表示されないので注意

# apt show cuda -a

Package: cuda
Version: 9.1.85-1
Priority: optional
Section: multiverse/devel
Maintainer: cudatools <cudatools@nvidia.com>
Installed-Size: 25.6 kB
Depends: cuda-9-1 (>= 9.1.85)
Download-Size: 2,512 B
APT-Sources: http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Packages
Description: CUDA meta-package
 Meta-package containing all the available packages required for native CUDA
 development. Contains the toolkit, samples, driver and documentation.

Package: cuda
Version: 9.0.176-1
Priority: optional
Section: multiverse/devel
Maintainer: cudatools <cudatools@nvidia.com>
Installed-Size: 25.6 kB
Depends: cuda-9-0 (>= 9.0.176)
Download-Size: 2,504 B
APT-Sources: http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Packages
Description: CUDA meta-package
 Meta-package containing all the available packages required for native CUDA
 development. Contains the toolkit, samples, driver and documentation.

Package: cuda
Version: 8.0.61-1
Priority: optional
Section: multiverse/devel
Maintainer: cudatools <cudatools@nvidia.com>
Installed-Size: 25.6 kB
Depends: cuda-8-0 (>= 8.0.61)
Download-Size: 2,510 B
APT-Sources: http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Packages
Description: CUDA meta-package
 Meta-package containing all the available packages required for native CUDA
 development. Contains the toolkit, samples, driver and documentation.

Package: cuda
Version: 8.0.44-1
Priority: optional
Section: multiverse/devel
Maintainer: cudatools <cudatools@nvidia.com>
Installed-Size: 25.6 kB
Depends: cuda-8-0 (>= 8.0.44)
Download-Size: 2,504 B
APT-Sources: http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Packages
Description: CUDA meta-package
 Meta-package containing all the available packages required for native CUDA
 development. Contains the toolkit, samples, driver and documentation.

ここで8.0.61-1をインストールしたい場合は

apt install cuda=8.0.61-1

でおk かんたんだ

Macのターミナルをカスタマイズして大変美しくする

Mac標準のターミナルはこれでもかってぐらいダサい

f:id:thr3a:20171231161151p:plain

ここではitermではなく、Mac OSに最初から入っているターミナルをいい感じにカスタマイズする。

インストール

自分でゴロゴリ設定するのはツラみがあるので、先人様の素晴らしいプロファイルを使う。

https://cocopon.github.io/iceberg.vim/cocopon.github.io

もともとはVim用のデザイン設定をターミナル用にも公開してくれている。「Iceberg for OS X Terminal」の項目のzipファイルをダウンロード&解凍。

  • ターミナルを開いて設定画面を開き、 -プロファイルタブをクリック。
  • わかりづらいがウィンドウ左下の「+」ボタンをクリック。先ほど解凍したファイルを選択
  • ウィンドウ左下の「デフォルト」ボタンをクリック。これで次回以降のターミナルがナウくなる。

f:id:thr3a:20171231161717p:plain

フォントとか文字の大きさはご自由に。フォントがイマイチな方には「Menlo」とか「Monaco」を選んでみるといいかも。いずれもMac標準フォントである。

参考リンク

MariaDBでJSON型を使う

使いたい人生だった

Qittaのとある記事みてMySQL5.7から追加されたJSON型で遊んでみたくなった。さっそく手元のDBで試そうと思ったら

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'JSON

ファーーーーーーーーーーーってそういえば手元のDBMySQLじゃなくてMariaDBだったは(

で終わり、は流石にアレなのでMariaDBDynamic Columnsで遊んでみた

環境

試す

まずは適当なjson_testテーブルを作成(正確にはJSONではないがJSON型があると思って作ってしまったので

CREATE TABLE `json_test` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `json` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

1つデータを追加してみる

INSERT INTO json_test VALUES (1, COLUMN_CREATE('name', 'taro', 'color', 'red'));

いけたのでもう1つ適当に

INSERT INTO json_test VALUES (2, COLUMN_CREATE('name', 'hanako', 'color', 'black'));

見てみよう

mysql> SELECT * from json_test
+----+-------------------------------------+
| id | json                                |
+----+-------------------------------------+
|  1 |           S namecolor!taro!red     |
|  2 |           s namecolor!hanako!black |
+----+-------------------------------------+

お、おう?

中身も表示させたい場合は COLUMN_JSONを使うといい感じ。JSONで取れるの便利

mysql> select id, COLUMN_JSON(json) from json_test;
+----+-----------------------------------+
| id | COLUMN_JSON(json)                 |
+----+-----------------------------------+
|  1 | {"name":"taro","color":"red"}     |
|  2 | {"name":"hanako","color":"black"} |
+----+-----------------------------------+

JSONの特定の要素のみ取得したい場合はCOLUMN_GET

mysql> select id, COLUMN_GET(json, 'name' AS char) AS name from json_test;
+----+--------+
| id | name   |
+----+--------+
|  1 | taro   |
|  2 | hanako |
+----+--------+

JSONに対してWHEREもかけることができる

SELECT id, COLUMN_JSON(json) FROM json_test WHERE COLUMN_GET(json, 'name' AS CHAR) = 'taro';
+----+-------------------------------+
| id | COLUMN_JSON(json)             |
+----+-------------------------------+
|  1 | {"name":"taro","color":"red"} |
+----+-------------------------------+

今までにないカラムを追加してみる

INSERT INTO json_test VALUES (3, COLUMN_CREATE('name', 'piyo', 'color', 'blue', 'age', 33));

見てみよう

mysql> select id, COLUMN_JSON(json) from json_test;
+----+-----------------------------------------+
| id | COLUMN_JSON(json)                       |
+----+-----------------------------------------+
|  1 | {"name":"taro","color":"red"}           |
|  2 | {"name":"hanako","color":"black"}       |
|  3 | {"age":33,"name":"piyo","color":"blue"} |
+----+-----------------------------------------+

値のないものはNULLになる

mysql> select id, COLUMN_GET(json, 'age' AS integer) AS name from json_test;
+----+------+
| id | name |
+----+------+
|  1 | NULL |
|  2 | NULL |
|  3 |   33 |
+----+------+