How to fix: ImportError: cannot import name LiveSpeech? - python

I am trying to use LiveSpeech with my model and dictionary which I have trained:
#!/usr/bin/env python
from pocketsphinx import LiveSpeech
hmm = '/home/ridwan/sphinx/other1/output/other1.ci_cont' #folder of the acoustic model
lm = '/home/ridwan/sphinx/other1/output/other1.lm.DMP' #language model
dict = '/home/ridwan/sphinx/other1/output/other1.dic' #the phonetic dictionary
recognizer = LiveSpeech (verbose = False, sampling_rate = 16000, buffer_size = 2048,
no_search = False, full_utt = False,
hmm = hmm, lm = lm, dic = dict)
for phrase in recognizer:
print (phrase)
But I am getting the following error:
Traceback (most recent call last):
File "./main.py", line 3, in
from pocketsphinx import LiveSpeech
ImportError: cannot import name LiveSpeech
NOTE: I have successfully installed pocketsphinx from CMU Sphinx

I had an old version of pocketsphinx.
Make sure to have the latest installed.
# Make sure we have up-to-date versions of pip, setuptools and wheel:
$ pip install --upgrade pip setuptools wheel
$ pip install --upgrade pocketsphinx

Related

PPTX Package not Found

I've installed the pptx package using the following command:
pip install python-pptx
However, When ever I try to import the package this is the output I receive:
Traceback (most recent call last):
File "/Users/divyabahri/Documents/hello.py", line 5, in <module>
import pptx
ModuleNotFoundError: No module named 'pptx
Can someone please guide me regarding the latter issues, Thanks in Advance!
Mismatch in the python version could be the cause of the error. The problem can be fixed by explicitly using PIP version 3 and also Python version 3.
Working demo:
Step 1: Install python-pptx and its dependencies using pip version 3
$ pip3 install python-pptx
$ pip3 install lxml ---> dependency
$ pip3 install pillow ---> dependency
Step 2: Python 3 program to create a pptx file
# File name: demo.py
from pptx import Presentation
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
prs.save('test.pptx')
Step 3: Execute the program using Python version 3
$ python3 demo.py
Step 4: Verify that the test.pptx file got created.
There can be many reasons for that:
1.- Python pptx only supports python version 3.6 or less here is the documentation https://python-pptx.readthedocs.io/en/latest/user/install.html
2.- Check also your path, check if python version that is availabel for pptx is on the path, here you can see how to check your path, https://winaero.com/blog/how-to-see-names-and-values-of-environment-variables-in-windows-10/
3.- pip is outdated, try to upgrade your pip
4.- maybe you import bad the library, here you can see how to import it, https://python-pptx.readthedocs.io/en/latest/user/quickstart.html

PyPI Packaging: install_requires `pillow`

I testing my PyPI package, before upload, with pip3 install -e ., in the package directory.
It depends on pillow (import PIL in code).
When I tested with already installed pillow it worked.
But, I uninstall the pillow then reinstall my package with pip3 install -e ., it didn't work:
Obtaining file:///Users/hongbook/dev/identicon
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/hongbook/dev/identicon/setup.py", line 4, in <module>
import Identicon
File "/Users/hongbook/dev/identicon/Identicon/__init__.py", line 2, in <module>
from .Identicon import render
File "/Users/hongbook/dev/identicon/Identicon/Identicon.py", line 5, in <module>
from PIL import Image, ImageDraw
ModuleNotFoundError: No module named 'PIL'
I expected when I install that, pillow should be installed since I wrote it install_requires's value in setup.py(also that in requirements.txt):
# setup.py
from setuptools import setup, find_packages
...
setup(
name='Identicon',
version=Identicon.__version__,
...
install_requires=[
'pillow',
],
)
# requirements.txt
pillow
How can I make dependency my project to pillow right?
I think your problem is stemming from this:
version=Identicon.__version__,
In order to do that, you're importing Identicon, which is your package, which imports PIL. So, your setup.py is broken. It requires the dependencies to be already installed in order to execute, however it's the setup.py job to install those dependencies in the first place.
This is a common "chicken and egg" situation in packaging. The solution is to use a different way to parse the version number from your package, or store the version number somewhere that doesn't trigger imports of your dependencies.
You can import version without importing the entire package using imp. See how I do it in SQLObject:
from imp import load_source
from os.path import abspath, dirname, join
versionpath = join(abspath(dirname(__file__)), "sqlobject", "__version__.py")
sqlobject_version = load_source("sqlobject_version", versionpath)
setup(name="SQLObject",
version=sqlobject_version.version,
…
)

ERROR after I changed to python 2.7from python3 ( anaconda3 and eclipse )

use following cmd:
conda create -n py27 python=2.7
inorder to change python3 to python 2.7
then i ran the code
from sklearn.feature_extraction import DictVectorizer
import csv
from sklearn import tree
from sklearn import preprocessing
from sklearn.externals.six import StringIO
# Read in the csv file and put features into list of dict and list of class label
allElectronicsData = open(r'D:\mycodes\test01\AllElectronics.csv', 'rb')
reader = csv.reader(allElectronicsData)
headers = reader.next()
error:
Finding files... done.
Importing test modules ... Traceback (most recent call last):
File "D:\huanjing\eclipse-java-neon-R-win32- x86_64\eclipse\plugins\org.python.pydev_5.7.0.201704111357\pysrc\_pydev_runfi les\pydev_runfiles.py", line 468, in __get_module_from_str
mod = __import__(modname)
File "D:\mycodes\test01\tree.py", line 1, in <module>
from sklearn.feature_extraction import DictVectorizer
ImportError: No module named sklearn.feature_extraction
ERROR: Module: tree could not be imported (file: D:/mycodes/test01/tree.py).
done.
Ran 0 tests in 0.000s
OK
It looks like after I change the python version ,I need to install all the python package in conda again?
Yes Python 2.7 and Python 3 will use different packages. Run the following commands in you conda environment:
$ conda install numpy
$ conda install scipy
$ conda install scikit-learn

pyjnius not working in virtual environment

I am working with pyjnius in django. I am not able to import it as a module so i am using it like this
os.system("python home/pyjnius/jnius/run_me.py " + path)
that works normally but in virtual environment it gives error
Traceback (most recent call last):
File "run_me.py", line 11, in <module>
from jnius import autoclass
ImportError: No module named jnius
this is the code i am follwing
please can anyone point some direction here as how to use pyjnius in virtual environment or where i am making mistakes.
in run_me.py this is the code
import os
os.environ['JAVA_HOME'] = '/usr/lib/jvm/java-7-openjdk-amd64/'
os.environ['CLASSPATH'] = "/path/to/tika-app.jar"
from jnius import autoclass
## Import the Java classes we are going to need
Tika = autoclass('org.apache.tika.Tika')
Metadata = autoclass('org.apache.tika.metadata.Metadata')
FileInputStream = autoclass('java.io.FileInputStream')
tika = Tika()
meta = Metadata()
text = tika.parseToString(FileInputStream(filename), meta)
thankyou
I had some trouble getting this to work as well.
The following worked for me:
Create a new virtualenv, just in case, and activate it.
# install pyjnius
pip install cython
cd [virtualenv]/src/
git clone https://github.com/kivy/pyjnius.git
cd pyjnius
python setup.py install
# get the tika-app (don't know if this is the latest version)
wget http://apache.proserve.nl/tika/tika-app-1.5.jar
mv tika-app-1.5.jar /usr/local/lib/
# put the following in .bashrc
export CLASSPATH=$CLASSPATH:/usr/local/lib/tika-app-1.5.jar

ImportError: No module named opencv after installing python-opencv

I install opencv in python with running $ sudo apt-get install python-opencv and installed successfully. but when run this code
import opencv
import opencv.highgui
import time
import commands
def get_image():
image = opencv.highgui.cvQueryFrame(camera)
return opencv.adaptors.Ipl2PIL(image)
camera = opencv.highgui.cvCreateCameraCapture(-1)
while 1:
image = get_image()
image.thumbnail((32, 24, ))
image = tuple(ord(i) for i in image.tostring())
x = int((int((max(image) / 256.0) * 10) + 1) ** 0.5 / 3 * 10)
cmd = ("sudo su -c 'echo " + str(x) +
" > /sys/devices/virtual/backlight/acpi_video0/brightness'")
status, output = commands.getstatusoutput(cmd)
assert status is 0
Got follow error
$ python bright.py
Traceback (most recent call last):
File "bright.py", line 1, in <module>
import opencv
ImportError: No module named opencv
Could you please help me?
You should be importing is cv2 not opencv, there is also no highgui. You might want to check out the docs
To install opencv for python you need the command
$ pip install opencv-python
To import it so as to use in applications the import to call the package is
import cv2

Categories

Resources