lxmlを使う時にエラー「bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?」

エラー発生

Traceback (most recent call last):
  File "scraping.py", line 19, in <module>
    soup = BeautifulSoup(r.text, 'lxml')
  File "/home/ubuntu/anaconda3/envs/scraping-flyer/lib/python3.7/site-packages/bs4/__init__.py", line 198, in __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

解決方法

$ conda install -c anaconda lxml 

参考

「catコマンドをリッチに!batを使う」+「zsh: correct」+「zsh: bad assignment」

batコマンドとは

github.com

様々な言語に対応したリッチなcatコマンドという感じ。 以下は公式サイトから引用。 f:id:saneeeatsu:20180907133818p:plain f:id:saneeeatsu:20180907133825p:plain

インストール

$ brew install bat

$ bat ViewController.swift
zsh: correct 'bat' to 'at' [nyae]? 

「n」とすればbatになるけどいちいち聞かれるのは面倒🤔

エラー解決方法

zsh: correct

.zshrcにnocorrectを使ったaliasを書くことで解決する。

# ~/.zshrc

alias bat = 'nocorrect bat'

zsh: bad assignment

実は上のように設定するとzsh起動時に「bad assignment」というエラーが出る。
「=」の両端のスペースを削除して解決。

alias bat='nocorrect bat'

参考

zsh: correct

zsh: bad assignment

【エラー】Jupyterで'conda' not found in path. →command not found: conda

エラー発生

jupyterを立ち上げるとブラウザに表示されるものの赤色で以下のエラーが発生。

[I 20:42:59.937 NotebookApp] Starting initial scan of virtual environments...
[E 20:42:59.940 NotebookApp] 'conda' not found in path. # 赤色

はて。

condaは入ってるはずだけども…。 仮想環境を作ってみる。

$ conda create -n keras_personlab
zsh: command not found: conda

パスが通ってないのかな?

解決方法

$ export PATH=~/anaconda3/bin:$PATH
$ conda --version
conda 4.4.10

参考

zshを使用時にbyobuのウィンドウ名が現在のパスになってしまう

ウィンドウ名がリネーム出来ない

下の写真では、keras-deeplab-v3-plusにいると、ウィンドウの名前もそれと同じになってしまい、F8でリネームしようとしても直すことが出来ない。

f:id:saneeeatsu:20180828161840p:plain

解決策

~/.zshrcにて以下の部分のコメントアウトをはずし、有効にする。

# Uncomment the following line to disable auto-setting terminal title. 
DISABLE_AUTO_TITLE="true"

再読込して修正完了。

$ source ~/.zshrc

参考

【エラー】tensorflow.python.framework.errors_impl.InternalError: Failed to create session.

エラー発生

$ python test.py
Using TensorFlow backend.

2018-08-27 12:36:30.830945: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-08-27 12:36:30.929279: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:897] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-08-27 12:36:30.929734: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:00:1e.0
totalMemory: 11.17GiB freeMemory: 11.10GiB
2018-08-27 12:36:30.929767: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 0
2018-08-27 12:36:30.930228: E tensorflow/core/common_runtime/direct_session.cc:158] Internal: cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version
Traceback (most recent call last):
  File "create_mask.py", line 24, in <module>
    model_dlv3 = model.Deeplabv3()
    :
    :
    :
tensorflow.python.framework.errors_impl.InternalError: Failed to create session.

解決方法(今回はこれでは治らない)

調べてみると2つの解決方法がある。が、なおらない…。

その1

以下をプログラムに埋め込む。

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"

その2

実行時に以下のようにする。

$ CUDA_VISIBLE_DEVICES=1 python **.py

原因

どうやらtensorflowとCUDAのバージョンによって起こるエラーのよう。

$ pip list
Package             Version  
------------------- ---------
  :
tensorflow          1.10.0   
  :

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

tensorflowは1.10.0、CUDAは9.0であることが確認出来た。

解決方法

今回はCUDAをバージョンアップすることでこの問題を解決する。

CUDA 9.2をインストール

公式サイトからダウンロードリンクを取得しあとは、その下にかかれているとおりに実行していく。 f:id:saneeeatsu:20180827134530p:plain

$ wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.2.148-1_amd64.deb
$ sudo dpkg -i cuda-repo-ubuntu1604_9.2.148-1_amd64.deb
$ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install cuda

パスを設定

$ echo -e "\n# CUDA and cuDNN paths"  >> ~/.bashrc
$ echo 'export PATH=/usr/local/cuda-9.2/bin:${PATH}' >> ~/.bashrc
$ echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.2/lib64:${LD_LIBRARY_PATH}' >> ~/.bashrc
$ source ~/.bashrc

参考

JupyterNotebookを動かしているサーバが日本語化されていなくてフォルダをクリック出来ない時の対処法

フォルダがクリック出来ない

scpで送ってもらったフォルダが、日本語名だったためか、JupyterNotebook上でクリックが出来なくて開けないという問題が発生した。 ファイルの最終更新日も書かれていない。 f:id:saneeeatsu:20180826200724p:plain

lsすると「?」で表される。

$ ls -al
drwxrwxr-x  2 ubuntu ubuntu  4096 Aug 26 18:19 ?????????_?????????(R0_L0)

解決策

フォルダ内のものをcpでとってきて、一時的に別のフォルダに入れておく。

$ mkdir tmp

$ cp *(R0_L0)/*.MOV tmp
zsh: no matches found: *(R0_L0)/*.MOV

$ cp *_L0\)/*.MOV tmp

JupyterNotebookで実行しているPythonプログラムにGPUが割り当てられない

GPUが割り当てられない問題

ipythonだったら

os.environ["CUDA_VISIBLE_DEVICES"]="0"

と書いておけば割り当てることが出来たのに…。

実際は以下のように割り当てられていない。

$ nvidia-smi
Sun Aug 26 18:20:39 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.111                Driver Version: 384.111                   |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           On   | 00000000:00:1E.0 Off |                    0 |
| N/A   28C    P8    31W / 149W |      0MiB / 11439MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

解決策

マウントした先でプログラムを実行していてもう一度色々インストールしなくちゃいけないの忘れてただけでした。

$ conda install tensorflow-gpu