2019年8月24日土曜日

Google Cloud EngineにTeraTermで接続する方法


概要

Google Cloud Engine(GCE)にTeraTermで接続する方法をメモします。

本テウンの公式はhttps://cloud.google.com/compute/docs/instances/transfer-files?hl=ja#winscpです。


用語

・Google Cloud Engine(GCE):Googleが提供しているクラウドサービス

手順


「puttygen.exe」をダウンロードして実行

「puttygen.exe」をダウンロードして実行します。

公開鍵をサーバーに覚えさせる

Generateをすると以下のとおり公開鍵が作成されます
Key commentをサーバー側のユーザー名にし(公開鍵が連動して修正される)、「Save private key」をするとppkファイルが作成します。
「Save private key」をした後に↑の反転させている所をサーバーに覚えさせます。以下の画面で編集ボタンから登録可能です。

TeraTermで接続

TeraTermを起動して設定->SSH認証を押し、以下の画面を開きます。

開いた画面の「秘密鍵」を押下し、作成したppkファイルを指定します。その上で、サーバーのIPアドレスを指定するとSSH接続出来るようになります。

Flask実行中エラーを解消する方法メモ

概要

Flask実行中に「OSError: [Errno 98] Address already in use」が出た際の解消方法メモです。

用語

・Ubuntu:LinuxのOS。
・Python:機械学習プログラミングに人気のプログラミング言語。
・Flask:簡易にpythonサーバを構築できるOSSフレームワーク。

事前準備(前提とする環境)

・Ubuntu14.04
・Python3(3.7.2)
・Flask 1.0.2

内容

Flaskを用いたwebサーバーを稼働させていて、一旦中止した後に再度実行する(開発中などはよく起きると思います)と、そのままでは再実行出来ません(下記)。

vagrant@vagrant-ubuntu-trusty-64:~/vagrant_data$ python3 sample.py
 * Serving Flask app "sample" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
^Z
[1]+  Stopped                 python3 sample.py
vagrant@vagrant-ubuntu-trusty-64:~/vagrant_data$ python3 sample.py
 * Serving Flask app "sample" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
Traceback (most recent call last):
  File "sample.py", line 11, in 
    app.run(host='0.0.0.0')
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 943, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 990, in run_simple
    inner()
  File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 943, in inner
    fd=fd,
  File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 786, in make_server
    host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
  File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 679, in __init__
    HTTPServer.__init__(self, server_address, handler)
  File "/usr/lib/python3.4/socketserver.py", line 430, in __init__
    self.server_bind()
  File "/usr/lib/python3.4/http/server.py", line 133, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.4/socketserver.py", line 444, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

これを解決するためには、linuxコマンドを用いてFlaskサーバーのプロセスをkillする必要があります。

そのために、まずは「プロセスID」を調べます。下記例では、プロセスIDは「1990」です。

vagrant@vagrant-ubuntu-trusty-64:~/vagrant_data$ ps -a
  PID TTY          TIME CMD
 1990 pts/0    00:00:00 python3
 1994 pts/0    00:00:00 ps

引き続き、killコマンドでプロセスを削除したいところですが、普通のkillではプロセス削除出来ません。

vagrant@vagrant-ubuntu-trusty-64:~/vagrant_data$ kill 1990
vagrant@vagrant-ubuntu-trusty-64:~/vagrant_data$ ps -a
  PID TTY          TIME CMD
 1990 pts/0    00:00:00 python3
 1995 pts/0    00:00:00 ps

なので、強制終了を行います。

vagrant@vagrant-ubuntu-trusty-64:~/vagrant_data$ kill -9 1990
[1]+  Killed                  python3 sample.py

これで正しくプロセス削除が出来ており、Flaskサーバーを再起動出来るようになります。

vagrant@vagrant-ubuntu-trusty-64:~/vagrant_data$ ps -a
  PID TTY          TIME CMD
 1996 pts/0    00:00:00 ps
vagrant@vagrant-ubuntu-trusty-64:~/vagrant_data$ python3 sample.py
 * Serving Flask app "sample" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

SystemError returned a result with an error setの解消方法

概要

Python+OpenCVで顔認識をする際に「SystemError: returned a result with an error set」というエラーが出る場合があるので、その解決方法をメモします。


用語

・Windows10:言わずと知れたMicrosoft社製のOS。
・Python:機械学習プログラミングに人気のプログラミング言語。
・Anaconda:データサイエンスおよび機械学習関連アプリケーションのためのPython+R言語のオープンソースディストリビューション
・OpenCV:インテルが開発した画像解析などに用いられるオープンソースライブラリ

 

事前準備(前提とする環境)

・Windows10 Pro
・Anaconda1.9.2
・OpenCV3.4.1

 

手順

現象

問題のエラーが以下のような感じで発生する事があります。

(base) C:\Users\kk\opencv>python Sample.py
OpenCV(3.4.1) Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file C:\Miniconda3\conda-bld\opencv-suite_1533128839831\work\modules\core\src\persistence_c.cpp, line 384
cv2.error: OpenCV(3.4.1) C:\Miniconda3\conda-bld\opencv-suite_1533128839831\work\modules\core\src\persistence_c.cpp:384: error: (-49) Input file is empty in function cvOpenFileStorage


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "Test_Cam.1.py", line 22, in 
    cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml')
SystemError:  returned a result with an error set

解決方法

これは、Githubに載っている画像解析のためのcascadeファイル(.xml)を用いた場合に発生するエラーのようです。 なので、公式サイトに載っている正しいcascadeファイルを用いれば解決出来ます。 


手順は以下です。

  1. OpenCVの公式サイトにアクセス
  2. 公式サイト上部右側の「Release」タブをクリック
  3. OpenCV-4.1.0の「Sources」をクリック
  4. zipファイルをダウンロード+解凍

該当のcascadeファイルは解凍したフォルダ内の「data\haarcascades」に格納されています

FX自動トレード_2021年6月実績

      概要 2021年6月が終わり、FX自動トレードによる収益実績を取り纏めましたので振り返ってみたいと思います。 2021年6月結果 2021年6月の実績は、実利利益額:\66,761、実績利益率は1.42%でした。 今月もボラが全く出ず。利益率の連続過去最低記録更新は免...