ModuleNotFoundError: No module named 'pyttsx3.drivers' - python

I am trying to run a voice program in Python 3.7.4 and with pyttsx library. But I've faced up with lots of problems while converting the file into an .exe file from .py file. Initially the program as executed in python runs fine. But when i converted the .py file to.exe using pyinstaller it gives me the following error while running :
File "site-packages\pyttsx3\__init__.py", line 20, in init
File "c:\users\s som\appdata\local\programs\python\python37-32\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "DesktopAi.py", line 22, in <module>
File "site-packages\pyttsx3\__init__.py", line 22, in init
File "site-packages\pyttsx3\engine.py", line 30, in __init__
File "site-packages\pyttsx3\driver.py", line 50, in __init__
File "importlib\__init__.py", line 127, in import_module
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyttsx3.drivers'
[11180] Failed to execute script DesktopAi ```

You can try the following:
pyinstaller --hidden-import=pyttsx3.drivers DesktopAi.py

Related

Python: Module throws errors when compiled into EXE with pyinstaller, doesn't when not compiled

When I compile my python code with pyinstaller, the "profanity_check" module gives an error:
Traceback (most recent call last):
File "main.py", line 6, in <module>
from profanity_check import predict, predict_prob
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "profanity_check\__init__.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "profanity_check\profanity_check.py", line 6, in <module>
File "joblib\numpy_pickle.py", line 579, in load
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\MyPc\\AppData\\Local\\Temp\\_MEI67002\\profanity_check\\data\\vectorizer.joblib'
[8696] Failed to execute script 'main' due to unhandled exception!
It is correct that there is no such file: vectorizer.joblib but when i run the uncompiled program it runs fine.
other modules get compiled without any problem.

TypeError: 'NoneType' object is not callable running exe made with pyinstaller

When trying to run an exe I made using pyinstaller it fails while importing OpenGL with this traceback:
(env) C:\Users\me\myProject>.\dist\myProject\myProject.exe
Traceback (most recent call last):
File "main.py", line 6, in <module>
from igtools import IG
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "OpenGL\GL\__init__.py", line 3, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "OpenGL\error.py", line 12, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "OpenGL\platform\__init__.py", line 36, in <module>
File "OpenGL\platform\__init__.py", line 30, in _load
TypeError: 'NoneType' object is not callable
[38272] Failed to execute script 'main' due to unhandled exception!
So I'm not sure exactly what the issue was. It seems like it had something to do with the pyinstaller hooks which I don't fully understand, but I did get it working with this specific combination of release versions:
pyinstaller==4.0
pyinstaller-hooks-contrib==2020.9
PyOpenGL==3.1.5
Maybe this will be helpful if anyone else runs into this.

"Cannot change thread mode after it is set" RunTime error in Python

I created a project that displays a Windows toast notification using the 'winrt' module. When I run my code in PyCharm, the script executes normally until completion. After compiling using PyInstaller and running the generated exe, I get an error for one of the 'winrt' imports:
Traceback (most recent call last):
File "notification.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "message.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "winrt\__init__.py", line 4, in <module>
RuntimeError: Cannot change thread mode after it is set.
[9720] Failed to execute script 'notification' due to unhandled exception!
My imports for 'winrt' are:
import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom
If anyone one knows why I get this error, I would appreciate any help!

#quickfix import failed in windows10

system: windows 10,
language: python 3.6.5
I installed the quickfix 1.15.1 by pip install quickfix-1.15.1-cp36-cp36m-win_amd64.whl downloaded from web.
When I try like:
import quickfix
errors:
*Connected to pydev debugger (build 202.6948.78)
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\quickfix.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\ProgramData\Anaconda3\lib\site-packages\quickfix.py", line 21, in <module>
_quickfix = swig_import_helper()
File "C:\ProgramData\Anaconda3\lib\site-packages\quickfix.py", line 20, in swig_import_helper
return importlib.import_module('_quickfix')
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.
Process finished with exit code 1*
And I had installed .Net 5.0
If you are sure that quickfix is correctly installed in your environment and the PYTHONPATH has access to this environment, then you can try to check the option 'Load conda env vars before run?' on Window -> Preferences -> PyDev -> Interpreters -> Python Interpreter.
It's possible that the import is failing because that package is using an environment variable to load the modules, and PyDev by default is not loading this variable before running the script.

AttributeError in Py2exe

I made my py file executable using py2exe. My setup.py is as follows:
from distutils.core import setup
import py2exe
setup(windows=['main.py'])
When I tried to run main.exe, I get an error and was referred to main.log which reads:
Traceback (most recent call last):
File "main.py", line 20, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\tslib.pyx", line 2839, in init pandas.tslib (pandas\tslib.c:79846)
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\algos.pyx", line 64, in init pandas.algos (pandas\algos.c:179610)
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\lib.pyx", line 1, in init pandas.lib (pandas\lib.c:77889)
AttributeError: 'module' object has no attribute '__pyx_capi__'
It looks like line 20 in my main.py file (import pandas as pd) triggered the problem. This type of error is referenced in a pull request here and they suggested adding a blank __init__.py file. I did so and got same result. I found a well commented post here (not directly dealing with py2exe) that suggests this might be due to mutual top-level imports or circular dependencies. This problem seems well known and has been mentioned at least twice on Stackoverflow in the past year (e.gs: here and here) but no clear solution has been given.
Perhaps we can get more clarity now with your feedback.
Python 3.4.2; py2exe 0.9.2.0
Was running into the same issue with pandas, but I got it working after updating to the most recent version.
It seems this error was recently addressed, and was resolved in Pandas 15.2
https://github.com/pydata/pandas/issues/8602
I was running in the same errors with Python 3.4.4.
My solution was to fix the import statement in C:\Pythob34\lib\site-packagespythoncom.py.
Original:
import pywintypes
pywintypes.import_pywin32_system_module("pythoncom", globals())
Changed To:
from pywintypes import import_pywin32_system_module
import_pywin32_system_module("pythoncom", globals())

Categories

Resources