pyinstaller打包時出現的一些錯誤
1、遇到錯誤時 File "stringsource", line 104, in init scipy.interpolate.interpnd
AttributeError: type object 'scipy.interpolate.interpnd.array' has no attribute '__reduce_cython__'
[34604] Failed to execute script demo2
解決方法:
打包時匯入隱藏包 pyinstaller -F XXX.py --hidden-import scipy._lib.messagestream
2、打包時路徑問題
匯入模型時不能直接使用相對路徑。可以使用絕對路徑,但是移動到其他裝置上時比較麻煩,因此出現了凍結路徑的方法。
增加一個檔案frozen_dir.py
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 25 22:41:09 2018
frozen dir
@author: yanhua
"""
import sys
import os
def app_path():
"""Returns the base application path."""
if hasattr(sys, 'frozen'):
# Handles PyInstaller
return os.path.dirname(sys.executable)
return os.path.dirname(__file__)
在程式碼中呼叫frozen_dir的方法:
import frozen_dir
SETUP_DIR = frozen_dir.app_path()
FONT_MSYH = matplotlib.font_manager.FontProperties(
fname = SETUP_DIR + r'\data\fonts\msyh.ttf',
size = 8)
DIR_HELP_DOC = SETUP_DIR + r'\data\docs'
DIR_HELP_VIDEO = SETUP_DIR + r'\data\videos'
3、未打包opencv的問題
自己手動新增,檔名opencv_ffmpeg341_64.dll
4、UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 126: invalid continuation byte
先在命令列輸入:chcp 65001