なお、現在の最新版はRCがとれています。RC1は昨年の7月下旬、RCが取れた正式版は10月にリリースされてますのでちょっとネタが古かったですかね。
2017-01-28
いつのまにかGWTもJava 8 対応になっていたようです
おちラボでは、現在でもGWTを使い続けていますが、GWTの最新リリースである2.8 では、Java8に対応していたようです。正確にいうとRC1の頃から対応していたようです。対応状況は、下記のリンクを参照のこと。
2017-01-25
Java:nekoHTMLParserを使っていてうまくパーズできない場合の対処メモ
JavaでのHTMLファイルをParseする時は、nekoHTMLParserを使っています。このパーザーはある意味柔軟なところがあり、使い勝手がいいんですが、エラーを全く吐かないまま、正しくParseできないことがあったので、メモ書きです。
【挙動】
【挙動】
- aタグを検索して hrefの属性値をとってくるプログラムを実行
- プログラムはエラーなく動作。しかし、hrefの値がとれていないところがところどころある(全てではなく、ところどころ、、というのが厄介)。
- 正確に言えば、文書中のaタグは漏れなく見つけられているが、値のとれていない(値のない)aタグがところどころ存在する。
- 文字コードが原因。今回のケースでは、諸事情によりHTMLファイルをコピペで取得し作成したため、文字はUTF-8、メタタグの指定がShift-JISという齟齬が発生していた
- メタタグの指定をUTF-8に変更
エラーが出ないからうまく動いているだろう、、と気づきにくいところなので要注意です。
2017-01-19
C#からPythonを呼ぶ(非同期処理)
先のC#からPythonを呼ぶサンプルコードは、一度実行したら終わりというケースです。実行中のPythonプログラムに標準入出力を利用してデータの授受をするのは、下記のコードがベターです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Diagnostics; | |
using System.Drawing; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace TestUiPythonCall | |
{ | |
public partial class Form1 : Form | |
{ | |
StreamWriter writer; | |
int count = 0; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
//テキストボックスの文字を渡す | |
string text = textBox1.Text; | |
writer.WriteLine(text); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
string fileName = @"C:\Users\ochi\Documents\temp\test.py"; | |
Process p = new Process(); | |
p.OutputDataReceived += new DataReceivedEventHandler(DataReceived); | |
p.StartInfo.FileName = "python"; | |
p.StartInfo.Arguments = fileName; | |
p.StartInfo.UseShellExecute = false; | |
p.StartInfo.RedirectStandardOutput = true; | |
p.StartInfo.RedirectStandardInput = true; | |
p.StartInfo.CreateNoWindow = true; | |
p.Start(); | |
p.BeginOutputReadLine(); | |
writer = p.StandardInput; | |
writer.AutoFlush = true; | |
} | |
void DataReceived(object sender, DataReceivedEventArgs e) | |
{ | |
//受け取った結果を表示する | |
Console.WriteLine(e.Data); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
input_line1=input() | |
print(input_line1+"from python",flush=True) |
2017-01-18
C#からPythonを呼ぶ
C#からPythonを呼ぶサンプルコードです。実行結果(コンソール出力)を受け取れます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace SamplePythonCall | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
run_cmd(); | |
} | |
static private void run_cmd() | |
{ | |
string fileName = @"C:\Users\ochi\Documents\temp\test.py"; | |
ProcessStartInfo start = new ProcessStartInfo(); | |
start.FileName = "python";//またはPython.exeのフルパス | |
start.Arguments = fileName; | |
start.UseShellExecute = false; | |
start.RedirectStandardOutput = true; | |
using (Process process =Process.Start(start)) | |
{ | |
using (StreamReader reader = process.StandardOutput) | |
{ | |
string result = reader.ReadToEnd(); | |
Console.Write("C#>"+result); | |
} | |
} | |
Console.ReadLine();//終了まち(enterで終了) | |
} | |
} | |
} |
TensorFlow for Windowsをインストールしてみた
TensorFlowはバージョン0.12からWindowsをサポートするようになりましたので、そのインストールのメモ書きです。ちなみに、個人的にPythonはよくわかってないレベルです。
Anacondaのインストール
TensorFlowを動かすには各種数値計算系のライブラリが必要になるのですが、Anacondaというライブラリ?を入れれば関係するライブラリが一括してインストールされるらしいので、これをインストールします。Pythonのバージョンは3.5で64bit版にしました。
Anaconda Promptを起動
コマンドプロンプトではなく、Anacondaプロンプトを起動して下さい(Anacondaのインストールで入ります)。以後、このプロンプトでの動作です。
pipでインストール
動作確認
下記のコマンドでバージョンが表示されたらインストール成功です。
Anacondaのインストール
TensorFlowを動かすには各種数値計算系のライブラリが必要になるのですが、Anacondaというライブラリ?を入れれば関係するライブラリが一括してインストールされるらしいので、これをインストールします。Pythonのバージョンは3.5で64bit版にしました。
Anaconda Promptを起動
コマンドプロンプトではなく、Anacondaプロンプトを起動して下さい(Anacondaのインストールで入ります)。以後、このプロンプトでの動作です。
pipでインストール
Pythonではpipというパッケージ管理システムがあります。TensorFlowもこれを利用します。
TensorFlowのインストールの前に、次のおまじないのコマンド2つ入力しておきましょう。pipとsetuptoolsのアップグレードをしているんだと思います。python -m pip install --upgrade pip
pip install --upgrade -I setuptools
上のおまじないが終わったら、下記の通り入力しましょう。
C:\> pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-0.12.1-cp35-cp35m-win_amd64.whlインストールするバージョンやによってURLは変わってきますので注意です。ここの記述の詳細は、公式サイトの Pip installation on Windowsを確認して下さい。
動作確認
下記のコマンドでバージョンが表示されたらインストール成功です。
python -c "import tensorflow; print(tensorflow.__version__);"
登録:
投稿 (Atom)