I'm trying to install TTS package by using this. Everything was okay until I tried to execute the following command:
import pyttsx
I got back this error:
File "/usr/local/lib/python3.4/dist-packages/pyttsx/__init__.py", line 18, in module <br>
from engine import Engine<br>
ImportError: No module named 'engine'
Any help would be appreciated. Thank you!
Guys there is an updated package compatible with Python3 :
pyttsx3
Works offline with no delay in the sound produced.
Installation:
pip install pyttsx3
Visit https://pyttsx3.readthedocs.io for the full usage docs.
Thanks!
Combining the advice from Jacob Tsui and Jokhongir Mamarasulov worked for me. To summarize:
In site_packages/pyttsx/init.py, modify "from engine import Engine" to
from .engine import Engine
Then, in site_packages/pyttsx/engine.py,
Modify import driver to
from . import driver
Modify except Exception, e to
except Exception as e
And finally, in site_packages/pyttsx/driver.py modify except Exception, e to
except Exception as e
See the responses from the aforementioned authors for the rationale behind these changes.
I just had the same problem, try using pyttsx3 instead of pyttsx
First install pyttsx3
pip install pyttsx3
and change the
import pyttsx
for
import pyttsx3
After that you have to change engine import (if you're using it in your main .py file). Use engineio instead. Install it
pip install python-engineio
then change import engine for import engineio and change your variables.
Here's an example
import pyttsx3
# import engineio #engineio module is not needed.
engineio = pyttsx3.init()
voices = engineio.getProperty('voices')
engineio.setProperty('rate', 130) # AquĆ puedes seleccionar la velocidad de la voz
engineio.setProperty('voice',voices[0].id)
def speak(text):
engineio.say(text)
engineio.runAndWait()
speak("What do you want me to say?")
while(1):
phrase = input("--> ")
if (phrase == "exit"):
exit(0)
speak(phrase)
print(voices)
Hope this helps someone
For Python3, please install the latest version via pip3 install pyttsx3 and call import pyttsx3.
I found out the solution. Library was created in python2 language and there are not a lot of differences between those 2 versions, but exclusively in this case that occurs.
Move to your DP folder and change in engine.py "except Exception as e" instead of "except Exception, e", line 67. Do the same in drive.py, line 105.
Because of files are secured try to execute, e. g.
sudo nano engine.py (or drive.py)
I guess I helped everyone with that kind of problem. :)
Modify site_packages/pyttsx/init.py "from engine import Engine" to
from .engine import Engine
Modify site_packages/pyttsx/engine.py "import driver" to
from . import driver
Reason: The import statement "from engine import Engine" tells python to import Engine module from directory engine. In our case engine is not a directory, it's a python file, engine.py. So we need to tell python to import this engine module from current directory (".").
I used this code after
pip install pywin32 pypiwin32 pyttsx3
and it worked perfectly for me
import os
import sys
import pyttsx3
engine = pyttsx3.init()
engine.say('hello world ')
engine.runAndWait()
I had the same issue.
First Try this command:
pip install pyttsx3
and then don't use
import pyttsx
use this
import pyttsx3
It will work.
pyttsx: No module named 'engine'
File "/usr/local/lib/python3.4/dist-packages/pyttsx/__init__.py", line 18, in module <br>
from engine import Engine<br>
ImportError: No module named 'engine'
If the above one is your error then try install pyttsx3 instead of
pyttsx.
Before installing check your python version, then download the version which is compatible to your python version.
Refer this link to get the previous versions of pyttsx3
REASON:
The reason we get the above error is because of the pyttsx3 version
which is not supported by your python version. Even if you get the error then
FOR pyttsx
Modify the init.py file located in
C:\Users\YOUR USER\AppData\Local\Programs\Python\Python38-32\Lib\site_packages\pyttsx\init.py
Change
from engine import Engine
to
from .engine import Engine
pyttsx
Modify the engine.py file located at C:\Users\YOUR USER\AppData\Local\Programs\Python\Python38-32\Lib\site_packages\pyttsx\engine.py
Change
import driver
to
from . import driver
These are the two main solutions for the above error
Related
I tried to install EZGmail module for Python. When I check my interpreter settings, it shows it as installed in the PyCharm list. I then use this same interpreter for my project, but I get a module not found error when trying to import EZGmail. What should I check?
Looks like you're trying to import the module in a different casing than it's mentioned on the document.
You're trying to do:
import EZGmail
while the Quickstart document says:
import ezgmail
I am still not the most sophisticated python user; but I cannot overcome this probably simple problem. I have a code that works perfectly with the spyder interface. I would like to make it a recurring task via creating a bat file. The bat file which in turn triggers a cmd interface does not import pandas_data reader and the code gets stuck and aborts.
import pandas_datareader.data as web
this line above creates the error below. It's a lengthy text.
File "C:\Users\myself\anaconda3\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import ( File "C:\Users\myself\anaconda3\lib\site-packages\pandas_datareader\data.py", line 9, in <module>
from pandas.util._decorators import deprecate_kwarg File "C:\Users\myself\anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies) ImportError: Unable to import required dependencies: numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\myself\anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.0" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.
Please read carefully. In my Python script I have the following:
import json
import pandas
from pandas.io.json import json_normalize
and it returns the following error:
from pandas.io.json import json_normalize ModuleNotFoundError: No
module named 'pandas.io'; 'pandas' is not a package
My steps:
I have uninstalled and installed Pandas
I have upgraded pip and pandas
I have installed io (pip install -U pandas.io)
I have installed data_reader and replaced the pandas.io.json part with that: from pandas_datareader import json_normalize
I have tried every solution I saw on stackoverflow and github and nothing worked. The only one I have not tried is installing Anaconda but it should work with what I tried before. Do you think it is a Windows setting things I must change?
PS: My Python version is 3.7.4
Try:
Go to ...\Lib\site-packages\pytrends on your local disk and open file request.py
Change
from pandas.io.json._normalize import nested_to_record
to
from pandas.io.json.normalize import nested_to_record
I had the same error, but it helped me.
also change
from pandas.io.json.normalize
to
from pandas.io.json._normalize
The cause of the problem was the fact that the python file had the name pandas. The filename was pandas.py. After renaming it, the code worked normally without errors.
i had same problem and i solve it b uninstalling extra python versions install on my windows.now i have only one python installed by anaconda,and everything is working perfectly
I tried to code on Pycharm, but when I use from keras import backend as K it throws an import error like "cannot import name backend". But I can do it on terminal.
How can I fix this?
error
on terminal
Are you sure your PyCharm sees the same Python environment as what you are using in Terminal?
See if this possibly works for you:
use tensorflow on pyCharm
I got the same problem:
Check here:Pycharm cannot find installed packages: keras
After adding new package to project interpreter, you need to quit Pycharm and restart it again.
Use
from tensorflow.python.keras import backend as K
instead.
I am trying to execute a python method from eclipse using jython. I managed to run it with following code:
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("Mypython.py");
interpreter.eval("MyClassName().MyMethodName()")
My problem is when I import another python script, which exists even in the same directory with Mypython.py. For example, when I add:
from food import Pizza
to Mypython.py, it starts to complain that cannot import. ImportError..
I found some questions about importing python libaries like os, but in my case this is not an issue.
I tried to make the folder as a package, add init.py etc but it failed. I saw some people use PySystemState, but I think it is for jython modules not user python scripts. if this is the solution please give me a simple example.
Could you please help me with that problem.
sys.path is your module-import search path. You can import sys and then modify sys.path as required.