我试图用pyinstaller将我的py脚本编译为onefile EXE 一切都很好,除了" VideoCapture"库。 这是我的代码中带有视频捕捉的块:
def TakePicture(s):
try:
cam = VideoCapture.Device(0)
cam.saveSnapshot("C:\\Users\\Public\\pic.jpg")
s.send("Snapshot saved at Users\Public\pic.jpg\n")
except Exception as camerror:
print camerror
s.send("Checking for second camera ...\n")
time.sleep(6)
try:
cam2 = VideoCapture.Device(1)
cam2.saveSnapshot("C:\\Users\\Public\\pic2.jpg")
s.send("Snapshot saved at Users\Public\pic2.jpg\n")
except Exception as camerror2:
print camerror2
当我将脚本运行为py但在编译为exe之后,一切都运行良好 我收到错误"找不到字体文件"
我该怎么做才能使它成为一个有效的EXE文件? 感谢。
解决问题
我需要做的就是编辑" load_path"此文件中的函数:Python27 \ Lib \ site-packages \ PIL \ ImageFont.py 原始代码:
def load_path(filename):
"Load a font file, searching along the Python path."
for dir in sys.path:
if Image.isDirectory(dir):
try:
return load(os.path.join(dir, filename))
except IOError:
pass
raise IOError("cannot find font file")
编辑代码:
def load_path(filename):
"Load a font file, searching along the Python path."
for dir in sys.path:
if Image.isDirectory(dir):
try:
#return load(os.path.join(dir, filename))
return load_default()
except IOError:
pass
raise IOError("cannot find font file")
答案 0 :(得分:-1)
def load_path(filename):
"Load a font file, searching along the Python path."
for dir in sys.path:
if Image.isDirectory(dir):
try:
#return load(os.path.join(dir, filename))
return load_default()
except IOError:
pass
raise IOError("cannot find font file")
很有效,非常感谢!