<Python, iPython>エラー。。。 QxcbConnectionうんぬんかんぬん。。。
新しいものにひかれ、conda
さんで、python3.6
の環境を作成。
ちょれ~と、ipython
を起動したら、エラーになった。
QXcbConnection: Could not connect to display
ちとぐぐった結果、~/.ipython/profile_default/startup/00-first.py
中で、import matplotlib.pyplot as plt
をしているが、ここでコケテルらしい。
次のお呪いを唱える必要ありとのこと。
import matplotlib as mpl mpl.use('Agg')
ふーん、、、
参考にさせてもらいました。
<Python, Anaconda> tempfile。。。
ちと。。。メモ。。。
Windows
のAnaconda
のtempfile
って、なんか仕様ちがわね???
dir()
してみると、.write
とかないんだけど、、、
In [73]: dir(tempfile.TemporaryFile()) Out[73]: ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_closer', 'close', 'delete', 'file', 'name']
<msys2, Jedi> msys2のvimでのJedi-vim
ちとはまったのでメモ。
msys2
のvim
でJedi-vim
。
どうも、msys2
のvim
は/bin/msys-python2.7.dll
か、/bin/msys-python3.4.dll
を見に行っているらしい。
なので、そのどれかがないとJedi-vim
が動かない。
エラーを吐く。
vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 1 2017 21:25:47) 適用済パッチ: 1-606 Compiled by <alexpux@gmail.com> Huge 版 without GUI. 機能の一覧 有効(+)/無効(-) +acl +file_in_path +mouse_sgr +tag_old_static +arabic +find_in_path -mouse_sysmouse -tag_any_white +autocmd +float +mouse_urxvt -tcl -balloon_eval +folding +mouse_xterm +termguicolors -browse -footer +multi_byte +terminfo ++builtin_terms +fork() +multi_lang +termresponse +byte_offset +gettext -mzscheme +textobjects +channel -hangul_input +netbeans_intg +timers +cindent +iconv +num64 +title -clientserver +insert_expand +packages -toolbar +clipboard +job +path_extra +user_commands +cmdline_compl +jumplist +perl/dyn +vertsplit +cmdline_hist +keymap +persistent_undo +virtualedit +cmdline_info +lambda +postscript +visual +comments +langmap +printer +visualextra +conceal +libcall +profile +viminfo +cryptv +linebreak +python/dyn +vreplace +cscope +lispindent +python3/dyn +wildignore +cursorbind +listcmds +quickfix +wildmenu +cursorshape +localmap +reltime +windows +dialog_con -lua +rightleft +writebackup +diff +menu +ruby/dyn -X11 +digraphs +mksession +scrollbind -xfontset -dnd +modify_fname +signs -xim -ebcdic +mouse +smartindent -xpm +emacs_tags -mouseshape +startuptime -xsmp +eval +mouse_dec +statusline -xterm_clipboard +ex_extra -mouse_gpm -sun_workshop -xterm_save +extra_search -mouse_jsbterm +syntax +farsi +mouse_netterm +tag_binary システム vimrc: "/etc/vimrc" ユーザー vimrc: "$HOME/.vimrc" 第2ユーザー vimrc: "~/.vim/vimrc" ユーザー exrc: "$HOME/.exrc" デフォルトファイル: "$VIMRUNTIME/defaults.vim" 省略時の $VIM: "/etc" 省略時の $VIMRUNTIME: "/usr/share/vim/vim80" コンパイル: gcc -c -I. -Iproto -DHAVE_CONFIG_H -D_FORTIFY_SOURCE=2 -I/usr/include/ncursesw -march=x86-64 -mtune=generic -O2 -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 リンク: gcc -L. -pipe -fstack-protector -pipe -Wl,--as-needed -o vim.exe -lm -lncursesw -liconv -lacl -lintl -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong -L/usr/lib/perl5/core_perl/CORE -lperl -lpthread -ldl -lcrypt
<Github, Cheatsheet> Gist をした。
Gist
をしてみた。
https://gist.github.com/Nekoyuki/8c41c5d135f8b4b47d8f462381febffc
上のやつをクローンするには、、、
git clone https://gist.github.com/Nekoyuki/8c41c5d135f8b4b47d8f462381febffc.git
とするらしい。
<Python, multiprocessing> マルチプロセスを試してみた。
ちと、必要があり、multiprocessing
モジュールを試してみた。
なにやら、戻り値return value
を取るには、Pool
とmap
を使わないといけない。。。
なにやら、map
の場合は、引数が1つしかとれないから、ラッパー関数を作ってくるまないといけない。。。うんぬん。。。
難しい。。。
で、出来たコードはこり。
こいつを流してみた。
Pool(1)
つまり、プロセス数が1つの場合。
% python multiprocessing_args.py 1 1.1610000133514404 [5, 7, 9, 11, 13, 15, 17, 19, 21, 23] time:0.1299998760223389 r: 5 pid:18512 time:0.2300000190734863 r: 7 pid:18512 time:0.3299999237060547 r: 9 pid:18512 time:0.4299998283386230 r: 11 pid:18512 time:0.5309998989105225 r: 13 pid:18512 time:0.6309998035430908 r: 15 pid:18512 time:0.7309999465942383 r: 17 pid:18512 time:0.8309998512268066 r: 19 pid:18512 time:0.9309999942779541 r: 21 pid:18512 time:1.0309998989105225 r: 23 pid:18512
Pool(3)
つまり、プロセス数が3つの場合。
% python multiprocessing_args.py 3 0.562000036239624 [5, 7, 9, 11, 13, 15, 17, 19, 21, 23] time:0.1300001144409180 r: 9 pid:11764 time:0.2300000190734863 r: 11 pid:11764 time:0.3300001621246338 r: 17 pid:11764 time:0.1300001144409180 r: 5 pid:19352 time:0.2300000190734863 r: 13 pid:19352 time:0.3300001621246338 r: 21 pid:19352 time:0.1300001144409180 r: 7 pid:14840 time:0.2300000190734863 r: 15 pid:14840 time:0.3300001621246338 r: 19 pid:14840 time:0.4120001792907715 r: 23 pid:14840
にゃるほど。。。
お世話になったところ。
17.2. multiprocessing — プロセスベースの並列処理 — Python 3.6.3 ドキュメント
ちなみに、昔、ちとやった、multithread
はこり。
<Python, pandas> to_csvでUnicodeEncodeError
Flask
さん中で、subprocess
を使って、Python
スクリプトを呼び出す。
呼び出されたPython
スクリプト中で、pandas.DataFrame.to_csv()
を使って、データフレームをcsv
出力。
データフレーム中に入っているデータが、元UTF-8
だった場合、かつFlask
環境がLANG=ascii
だと、
UnicodeEncodeError
を吐き出す。。。
ちょーはまる。。。
この記事が参考になる。
PythonのUnicodeEncodeErrorを知る - HDEラボ
結局、データフレーム中のデータをあらかじめascii
にしてエラーを出さないようにした。。。
<Python, requests> requestsでSSLError
最近requests
でSSLError
が出るようになってしまった。。。
In [10]: import requests In [11]: r = requests.get(url, verify=False)
ってやって、verify
を無視すれば、少々せきゅりちーに問題ありだがアクセスできるらしい。。。
で、、requests
が呼ばれるモジュールの場合は、、、
In [12]: import requests.api ...: import warnings ...: ...: ...: def requestspatch(method, url, **kwargs): ...: kwargs['verify'] = False ...: return _origcall(method, url, **kwargs) ...: ...: _origcall = requests.api.request ...: requests.api.request = requestspatch ...: warnings.warn('Pathched requests: SSL verification disabled!')
ってやれば、いいらしい。
とりあえず、アクセスはできるが、、、
もうちょいなんとかならんもんかにょー。。。
もうちょい調べてみた。。。
pip install -U certifi
してみたけど、だめだったす。。。
verify=False
で対応するしかないのか? 今のところ???
2017/11/16、、もうちょい追加。
SSLErrorメッセージがうっとうしいときは、下記で消せる。 (python3.6の場合)
from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning)