BASE_DIR = os.path.dirname(sys.argv[0]) SEARCH_PATH = os.path.join(BASE_DIR, '*') SOURCE_DIR =[dir for dir in glob.glob() if os.path.isdir(dir)]
起動方法
$ipython notebook
iPythonとmatplotlibを使ってグラフを描画するときのおまじない。
%matplotlib inline import numpy as np import matplotlib.pyplot as plt
.ipynbファイルをgistかgithubにアップロードして置くことで、vbviwerによりwebページとして表示することができる。
import time start = time.time() print(">> Finish Analys :{0}".format(time.time() - start))
pyinstaller SimpleTextEditor.py --onefile --noconsole
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: ''
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.
# ファイルが存在しない場合は返却 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
まずは悪い例
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)
→py2exe Python スクリプトからスタンドアロンのWindowsプログラムへの変換
どうもPySideを使っているとPyInstaller?が上手くexe化してくれない。しかたがないので、py2exeをつかってみる。
################# if PySide not installed inside houdini libs import platform if platform.system() == 'Windows': sp = 'C:/Python27/Lib/site-packages' if not sp in sys.path: # if os.path.exists(sp): sys.path.insert(0, sp) print sp
Pythonをコーディングしている時に発生する初心者ミスをまとめておく。