pyttsx3使用pyinstaller打包失败

1.常见错误:  ModuleNotFoundError: No module named 'pyttsx3.drivers'

最直接的方式是 import pyttsx3.drivers

2.常见错误: 接下来会报错 ModuleNotFoundError: No module named 'pyttsx3.drivers.sapi5'

和上面一样的方法: import pyttsx3.drivers.sapi5

3.常见错误: 接下来是 pywintypes.com_error: (-2147221008, '尚未调用。', None, None)

这里先是导入 import pythoncom

接着在你用了线程的run里面 加上线程初始化 pythoncom.CoInitialize()

这个的用处是初始化线程

4.常见错误: 最后是pywintypes.com_error: (-2147352573, '找不到成员。', None, None)

然后找到 pyttsx3的目录:修改文件“<python路径>\Lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_win32comgenpy.py”

直接让他不经过下面
import sys
# The win32com fixes aren't needed for Python 3.X
if sys.version_info >= (3, 0):
    pass
else:
<以下为原内容>

#-----------------------------------------------------------------------------
# Copyright (c) 2013-2017, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


# The win32.client.gencache code must be allowed to create the cache in %temp%
# (user's temp). It is necessary to get the gencache code to use a suitable
# directory other than the default in lib\site-packages\win32com\client\gen_py.
# PyInstaller does not provide this directory structure and the frozen
# executable could be placed in a non-writable directory like 'C:\Program Files.
# That's the reason for %temp% directory.
#
# http://www.py2exe.org/index.cgi/UsingEnsureDispatch

import sys
# The win32com fixes aren't needed for Python 3.X
if sys.version_info >= (3, 0):
    pass
else:
    import atexit
    import os
    import shutil
    import tempfile


    # Put gen_py cache in temp directory.
    supportdir = tempfile.mkdtemp()
    # gen_py has to be put into directory 'gen_py'.
    genpydir = os.path.join(supportdir, 'gen_py')


    # Create 'gen_py' directory. This directory does not need
    # to contain '__init__.py' file.
    try:
        # win32com gencache cannot be put directly to 'supportdir' with any
        # random name. It has to be put in a directory called 'gen_py'.
        # This is the reason why to create this directory in supportdir'.
        os.makedirs(genpydir)
        # Remove temp directory at application exit and ignore any errors.
        atexit.register(shutil.rmtree, supportdir, ignore_errors=True)
    except OSError:
        pass


    # Override the default path to gen_py cache.
    import win32com
    win32com.__gen_path__ = genpydir


    # The attribute __loader__ makes module 'pkg_resources' working but On Windows
    # it breaks pywin32 (win32com) and test 'basic/test_pyttsx' will fail. Just
    # removing that attribute for win32com fixes that and gencache is created properly.
    if hasattr(win32com, '__loader__'):
        del win32com.__loader__


    # Ensure genpydir is in 'gen_py' module paths.
    import win32com.gen_py
    win32com.gen_py.__path__.insert(0, genpydir)

原文地址:http://www.lolpzili.com/index.php/archives/20/#comment-2

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
pyinstaller打包失败可能有多种原因。根据引用提供的信息,其中一个可能的原因是文件缺失错误(FileNotFoundError),即在打包过程中,某些文件没有被正确地包含在最终的exe文件中。在这个特定的例子中,缺失的文件是位于"lib\\site-packages\\pyyaml-5.3.1-py3.6-win-amd64.egg\\EGG-INFO\\top_level.txt"路径下的文件。 另一个可能的原因是模块找不到错误(ModuleNotFoundError),即在运行exe文件时,某些模块无法被正确地导入。在这个例子中,缺失的模块是"statsmodels.__init__._version"。 要解决这些问题,你可以尝试以下几个步骤: 1. 确保你的打包命令(pyinstaller -F -w -i xxx.ico xxx.py)正确无误,并且指定了正确的输入文件和图标文件。 2. 检查所需的文件和模块是否都存在于你的项目中,并且确保它们被正确地导入和使用。 3. 检查你的环境是否缺少某些依赖库或模块。根据引用的提示,你可能需要安装pywin32或pypiwin32版本。尝试安装或更新这些依赖库,并确保它们能够正确地被导入和使用。 4. 如果问题仍然存在,尝试搜索相关错误信息,看看是否有其他人遇到过类似的问题,并且有没有解决方案可供参考。 总之,pyinstaller打包失败可能是由于文件缺失或模块找不到等问题所致。通过仔细检查你的打包命令、确保所需的文件和模块存在并正确导入、安装或更新依赖库,并参考其他人的解决方案,你应该能够解决这个问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值