i am trying to convert text to speech using pyttsx3 in python. but i am getting the error maybe on driverName - winapi

i am trying to convert text to speech using pyttsx3 in python. but i am getting the error maybe on driverName.
Here is my code
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
Here is the Output which gives error.
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
============ RESTART: D:/abhi/My Program/text-to-speech(pyttsx3).py ============
Traceback (most recent call last):
File "C:\Users\Laptop\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\Laptop\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/abhi/My Program/text-to-speech(pyttsx3).py", line 2, in <module>
engine = pyttsx3.init()
File "C:\Users\Laptop\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\Laptop\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\Laptop\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Users\Laptop\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
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 "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Laptop\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
import win32com.client
File "C:\Users\Laptop\AppData\Local\Programs\Python\Python38\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed while importing win32api: The specified module could not be found.
>>>

Your code is no problem.
It can run successfully on my Windows 10, my python version is 3.7.3.
ImportError: DLL load failed while importing win32api: The specified module could not be found.
Your win32api module does not seem to be installed correctly, please use pip uninstall pywin32 to uninstall and use pip install pywin32 to install again.
You can also refer other methods in the link to solve it.
For KeyError: None, you can refer Python KeyError Exceptions and How to Handle Them to do some error handling.
Finally, please follow this tutorial to convert text to speech.

I sloved my own problem.
Firstly! I uninstalled Python-3.8 from control panel and installed Python-3.7.2(and added to path during installation).
Secondly,Upgraded setuptool using cmd -> pip install --upgrade setuptools.
after that I installed SpeechRecognition, pyttsx3
and after that I also installed
PyAudio-0.2.11-cp37-cp37m-win_amd64.whl using whl file(because pyaudio is necessary to run this program).
Link to download whl file-> Here .
Now, This program works.

Related

Anaconda broke itself upon updating

So, Anaconda suggested me to do a conda update -n base -c defaults conda after I created a new environment, which I did. It ran for a few minutes, with huge amounds of warnings saying it couldn't delete some files. Then stopped, and now everything is broken.
I cannot update anaconda anymore, I cannot run conda info nor conda env list, I can't do anything. I can't use my envs through VScode either for example.
The output of conda info is:
>>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\exceptions.py", line 1082, in __call__
return func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\main.py", line 87, in _main
exit_code = do_call(args, p)
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\conda_argparse.py", line 82, in do_call
module = import_module(relative_mod, __name__.rsplit('.', 1)[0])
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
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 "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\main_info.py", line 19, in <module>
from ..core.index import _supplement_index_with_system
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\index.py", line 15, in <module>
from .subdir_data import SubdirData, make_feature_record
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 54, in <module>
from conda_content_trust.common import (
File "C:\ProgramData\Anaconda3\lib\site-packages\conda_content_trust\common.py", line 63, in <module>
import cryptography.hazmat.primitives.asymmetric.ed25519 as ed25519
File "C:\ProgramData\Anaconda3\lib\site-packages\cryptography\hazmat\primitives\asymmetric\ed25519.py", line 8, in <module>
from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
File "C:\ProgramData\Anaconda3\lib\site-packages\cryptography\exceptions.py", line 16, in <module>
class _Reasons(utils.Enum):
File "C:\ProgramData\Anaconda3\lib\site-packages\cryptography\utils.py", line 115, in __getattr__
obj = getattr(self._module, attr)
AttributeError: module 'cryptography.utils' has no attribute 'Enum'
$ C:\ProgramData\Anaconda3\Scripts\conda-script.py info
An unexpected error has occurred. Conda has prepared the above report.
If submitted, this report will be used by core maintainers to improve
future releases of conda.
Would you like conda to send this report to the core maintainers?
I tried to install conda install anaconda-clean to erase it all cleanly, but I get the same error (cryptography).
It is really a problem in a moment when I need a functional python fast.
I am on Windows 10.
I am not so familiar with conda's inner working on a low level.
Please advise.
Thanks

ModuleNotFoundError: No module named 'websockets.datastructures'

I don't know how to fix this error on Ubuntu.
I'm trying to run a FastApi server using uvicorn
uvicorn.run("api:app", host="0.0.0.0", port=3100, reload=True, workers=10)
I've tried pip3 install websockets :
Collecting websockets
Downloading https://files.pythonhosted.org/packages/7e/86/cef054220bc080451fe9663ce7f99beda0599098241190b6b6dc1073ab92/websockets-10.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (112kB)
100% |████████████████████████████████| 112kB 5.9MB/s
Installing collected packages: websockets
Successfully installed websockets-8.1
I don't know what else needs to be installed
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
return future.result()
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/server.py", line 67, in serve
config.load()
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/config.py", line 471, in load
ws_protocol_class = import_from_string(WS_PROTOCOLS[self.ws])
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/importer.py", line 24, in import_from_string
raise exc from None
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
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 "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/protocols/websockets/auto.py", line 17, in <module>
from uvicorn.protocols.websockets.websockets_impl import WebSocketProtocol
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 9, in <module>
from websockets.datastructures import Headers
ModuleNotFoundError: No module named 'websockets.datastructures'
To me, any of the two other answers work. I just upgrade websockets with:
pip install -U websockets
I had the same problem and i'm not sure why this happened but i'll atleast show you my workaround.
The best thing to do would be running:
pip uninstall websockets
pip install websockets
But for some reason this command could not uninstall it for me, so i did it manually.
Since u are in Ubuntu open this folder as root:
/usr/local/lib/python3.8/dist-packages/websocket
Then u can manually download the files at websockets current version files
In my case i noticed that in my old websockets folder i didn't have websockets.datastructures and also some other files such as the folders legacy and extensions so i just unzipped the whole library to the path cited above and it worked.
needed to update setuptools and pip
pip3 install -U setuptools
pip3 install -U pip

Error while running ARA server on Alpine linux

I am trying to install the latest version of the Ansible Records Analyzer server on an alpine Linux I made sure that all requirements are well installed ( Django, GCC,python3, Pypi, ansible) the install went well except for a warning about the absence of root PATH on the PATH variable which I fixed:
The warning :
WARNING: The script pbr is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
The fix:
~ # export PATH=/root/.local/bin:$PATH
So following the install guide on this step that intends to run the server I have an avalanche of errors as if the run command doesn't find the needed components to be executed although I'm sure all the components are installed :
~ # ara-manage runserver
[ara] No setting found for SECRET_KEY. Generating a random key...
Traceback (most recent call last):
File "/root/.local/bin/ara-manage", line 8, in <module>
sys.exit(main())
File "/root/.local/lib/python3.8/site-packages/ara/server/__main__.py", line 41, in main
if not os.path.exists(settings.ARA_SETTINGS):
File "/root/.local/lib/python3.8/site-packages/django/conf/__init__.py", line 79, in __getattr__
self._setup(name)
File "/root/.local/lib/python3.8/site-packages/django/conf/__init__.py", line 66, in _setup
self._wrapped = Settings(settings_module)
File "/root/.local/lib/python3.8/site-packages/django/conf/__init__.py", line 157, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
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 "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/root/.local/lib/python3.8/site-packages/ara/server/settings.py", line 263, in <module>
ALLOWED_HOSTS=ALLOWED_HOSTS.to_list(),
AttributeError: 'list' object has no attribute 'to_list'
What could be the reason behind this behavior?
Well I managed to overcome this issue, the problem was in dynaconf the current version 3.1.3 doesn't read the conf files properly which fails in the server run.
Meanwhile, the only workaround is to install the previous version of dynaconf :
pip install 'dynaconf==3.1.2'
FYI dynaconf already has a fix proposed for the regression: rochacbruno/dynaconf#541
I've tested that it does resolve this issue and it will be released in dynaconf 3.1.4 soon.

ModuleNotFound error after sucessfully install cgal using conda?

I installed CGAL in windows using conda:
https://anaconda.org/conda-forge/cgal
But it gives error during importing modules.
>>> import CGAL
>>> print(CGAL.__version__)
4.14.0
>>> import CGAL.CGAL_AABB_tree
Traceback (most recent call last):
File "C:\Users\Ibrahim Khalilullah\.conda\envs\CGALCONDA\lib\site-packages\CGAL\CGAL_AABB_tree.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\Ibrahim Khalilullah\.conda\envs\CGALCONDA\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 "<stdin>", line 1, in <module>
File "C:\Users\Ibrahim Khalilullah\.conda\envs\CGALCONDA\lib\site-packages\CGAL\CGAL_AABB_tree.py", line 17, in <module>
_CGAL_AABB_tree = swig_import_helper()
File "C:\Users\Ibrahim Khalilullah\.conda\envs\CGALCONDA\lib\site-packages\CGAL\CGAL_AABB_tree.py", line 16, in swig_import_helper
return importlib.import_module('_CGAL_AABB_tree')
File "C:\Users\Ibrahim Khalilullah\.conda\envs\CGALCONDA\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_CGAL_AABB_tree'
The issue is not the ModuleNotFoundError, but the underlying ImportError: DLL load failed:. Looking at your error message, you can see that your python does succesfully locate what you are trying to import at
C:\Users\Ibrahim Khalilullah\.conda\envs\CGALCONDA\lib\site-packages\CGAL\CGAL_AABB_tree.py
but fails to load a dependent DLL.
I have reproduced your issue. It seems to be one that only effects the most current of cgal in conda forge, which is 4.14 When you install the 4.13 version everything works fine, so simply do:
conda remove cgal
conda install -c conda-forge cgal==4.13
I have created an issue on the conda-forge feedstock

"ModuleNotFoundError: No module named 'scrapy'" and "bash: scrapy: command not found" on MacOs

Good morning everyone,
First of all, I wanted to make it very clear that I checked if this question had been asked before and if it had been answered I would have solved the question.
I found this:
ModuleNotFoundError: No module named 'Scrapy'
That has been done for more than a year and the answers do not solve any problem related to me as the person who wrote it.
Something is wrong with my MacOs I think. When I wrote this code like on https://scrapy.org it doesn't work at all, after installing python3 and scrapy
Using
brew install python3
and for scrapy
pip install scrapy
Then I use the code from scrapy website:
import scrapy
class BlogSpider(scrapy.Spider):
name = 'blogspider'
start_urls = ['https://fr.wikipedia.org/wiki/Catégorie:Personnage_d%27animation']
def parse(self, response):
for title in response.css('div#mw-pages div.mw-category li'):
yield {'character': title.css('a ::text').extract_first()}
And then I receive 2 type of messages:
If I run the code:
scrapy runspider myspider.py
I receive the message:
bash: scrapy: command not found
And if I open python3 and just write:
import scrapy
I receive this message:
ModuleNotFoundError: No module named 'scrapy'
Someone can help me fixing this, because i don't remember how can I do it I already uninstall both python and scrapy but nothing change.
then i used:
pip3 install scrapy
As DavidG told me told try
but I receive this message:
-bash: pip3: command not found
So after a few more searches, I just tried reinstalling Python3, so I used:
brew install python3
so I wrote:
pip3 --version
and showed this:
pip 10.0.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
Next:
scrapy --version
and received:
Scrapy 1.5.1 - no active project
so I tried to use the command again:
scrapy runspider myspider.py
and received this:
2018-07-18 20:11:49 [scrapy.utils.log] INFO: Scrapy 1.5.1 started (bot: scrapybot)
2018-07-18 20:11:49 [scrapy.utils.log] INFO: Versions: lxml 4.2.3.0, libxml2 2.9.4, cssselect 1.0.3, parsel 1.5.0,w3lib 1.19.0, Twisted 18.7.0, Python 3.7.0 (default, Jun 29 2018, 20:13:13) - [Clang 9.1.0 (clang-902.0.39.2)], pyOpenSSL 18.0.0 (OpenSSL 1.1.0h 27 Mar 2018), cryptography 2.3, Platform Darwin-17.6.0-x86_64-i386-64bit
2018-07-18 20:11:49 [scrapy.crawler] INFO: Overridden settings: {'SPIDER_LOADER_WARN_ONLY': True}
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 11, in <module>
sys.exit(execute())
File "/usr/local/lib/python3.7/site-packages/scrapy/cmdline.py", line 150, in execute
_run_print_help(parser, _run_command, cmd, args, opts)
File "/usr/local/lib/python3.7/site-packages/scrapy/cmdline.py", line 90, in _run_print_help
func(*a, **kw)
File "/usr/local/lib/python3.7/site-packages/scrapy/cmdline.py", line 157, in _run_command
cmd.run(args, opts)
File "/usr/local/lib/python3.7/site-packages/scrapy/commands/runspider.py", line 88, in run
self.crawler_process.crawl(spidercls, **opts.spargs)
File "/usr/local/lib/python3.7/site-packages/scrapy/crawler.py", line 170, in crawl
crawler = self.create_crawler(crawler_or_spidercls)
File "/usr/local/lib/python3.7/site-packages/scrapy/crawler.py", line 198, in create_crawler
return self._create_crawler(crawler_or_spidercls)
File "/usr/local/lib/python3.7/site-packages/scrapy/crawler.py", line 203, in _create_crawler
return Crawler(spidercls, self.settings)
File "/usr/local/lib/python3.7/site-packages/scrapy/crawler.py", line 55, in __init__
self.extensions = ExtensionManager.from_crawler(self)
File "/usr/local/lib/python3.7/site-packages/scrapy/middleware.py", line 58, in from_crawler
return cls.from_settings(crawler.settings, crawler)
File "/usr/local/lib/python3.7/site-packages/scrapy/middleware.py", line 34, in from_settings
mwcls = load_object(clspath)
File "/usr/local/lib/python3.7/site-packages/scrapy/utils/misc.py", line 44, in load_object
mod = import_module(module)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
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 "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.7/site-packages/scrapy/extensions/telnet.py", line 12, in <module>
from twisted.conch import manhole, telnet
File "/usr/local/lib/python3.7/site-packages/twisted/conch/manhole.py", line 154
def write(self, data, async=False):
^
SyntaxError: invalid syntax
Can someone tell me what's going on and how to correct it?
So after the help and explanation of:
#DavidG
#phd
#DanielR.Livingston
I figured it was not a problem with my computer, but it was all a compatibility issue.
It does not solve my problem, because this was an exercise I found in a MOOC, but since it has been done for some time it does not work in the same way, but at least I can move on to a different course since I can not do more anything with the scrapy.
Thank you all

Resources