- 追加された行はこの色です。
- 削除された行はこの色です。
** iPython Notebook [#g6ea7e98]
起動方法
$ipython notebook
** iPythonおまじない [#lb7e6868]
iPythonとmatplotlibを使ってグラフを描画するときのおまじない。
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
** nbviwer [#h75d005f]
.ipynbファイルをgistかgithubにアップロードして置くことで、vbviwerによりwebページとして表示することができる。
#ref(s-nbviewer.jpg,,50%)
[[→nbviwer>http://nbviewer.ipython.org/]]
** 時間計測 [#x64e078e]
import time
start = time.time()
print(">> Finish Analys :{0}".format(time.time() - start))
** pyinstaller [#qde9d4cd]
** PyInstaller [#qde9d4cd]
pyinstaller SimpleTextEditor.py --onefile --noconsole
+ --onefile : .exeを一つのファイルにする
+ --windowed, -w : コマンドプロンプト非表示
+ -i<appicon.icon>, --icon=<appicon.icon> : プログラムのアイコンを設定
+ --noconsole : コマンドプロンプト非表示
*** エラー IOError: [Errno 22] invalid mode ('rb') or filename: '' [#s77fd814]
File "C:\Users\fifi\Anaconda\lib\site-packages\PyInstaller\build.py", line 796, in cacheDigest
data = open(fnm, "rb").read()
IOError: [Errno 22] invalid mode ('rb') or filename: ''
- 見つけた対策 1
[[http://codedmi.com/questions/785472/pyinstaller-errno-22]]
Well reinstalled pywin32 and now working :S just going go with it
Just spent the better part of a week tracking this bug down. Was getting this error just by trying to compile a script importing numpy or pandas and printing "hello world".
Eventually fixed it by running command prompt as administrator... Yeah.
Hope this helps some poor desperate soul.
I had the same issues but found these other solutions did not fix the problem. I did however find a fix as follows:
First, my situation may be a little different to the OP as I'm using the Anaconda Python distribution on Windows 7, and used the conda command line too to install pywin32, and then used pip to install pyinstaller.
I found the same IOError was preceded by this earlier error message in the pyinstaller output log:
ImportError: No system module 'pywintypes' (pywintypes27.dll)
The solution that fixed both errors was to copy the DLL files:
pywintypes27.dll
pythoncom27.dll
sitting in: C:\<anaconda-dir>\Lib\site-packages\win32
to C:\<anaconda-dir>\Lib\site-packages\win32\lib
Where <anaconda-dir> will either be your root Anaconda directory:
C:\Users\<username>\AppData\Local\Continuum\Anaconda\ by default,
or an environment you have set up e.g.
C:\Users\<username>\AppData\Local\Continuum\Anaconda\envs\<environment-name>
A came across this answer thanks to Tompa here, who found it solved a similar problem in py2exe.
** エラーの発行 raise [#ya1a635b]
[[→組み込み例外>http://docs.python.jp/2/library/exceptions.html#exceptions.EnvironmentError]]
# ファイルが存在しない場合は返却
if not os.path.exists(filepath):
# raise StandardError("File is not exist %s" % (filepath))
return
try:
# ファイルオープン
data = wave.open(filepath, 'rb')
except IOError:
raise StandardError("Cant file load %s" % (filepath))
else:
# 正常時の処理
finally:
pass
** 例外処理のよい例・悪い例 [#hc442a98]
まずは悪い例
def get_status(file):
if not os.path.exists(file):
print "file not found"
sys.exit(1)
return open(file).readline()
これだと、open(file)の際に出たエラーを捕まえていない。
よい例
def get_status(file):
try:
return open(file).readline()
except EnvironmentError as err:
print "Unable to open file: {}".format(err)
sys.exit(1)
** LookupError: unknown encoding: windows-31j [#r75276b1]
- Pycahrmの設定で、文字コード設定をUTF=8に変更する