Pocketsphinx import ValueError - python

I recently installed pocketsphinx modules on my mac running Lion and Python 2.7.3(Not Apple's built in python, but brewed). I tried to run the following code:
import pocketsphinx as p
decoder = p.Decoder(jsgf='/path_to_jsgf_file/grammar.jsgf',samprate='8000')
fh = open('myrecording.wav', 'rb')
nsamp = decoder.decode_raw(fh)
print 'You said,', hyp
print 'Your score was', score
But here's the error I get on running import pocketsphinx as p :
Traceback (most recent call last):
File "speech_reco.py", line 4, in <module>
import pocketsphinx as p
File "sphinxbase.pxd", line 150, in init pocketsphinx (pocketsphinx.c:7935)
ValueError: PyCapsule_GetPointer called with invalid PyCapsule object
However, it runs correctly when the import command is run the second time. Therefore, presently, I'm running a try-catch there and getting past the error. But I don't know whether this still works.
This issue seems to have come up before,as discussed on this link: http://sourceforge.net/p/cmusphinx/bugs/284/
Has anyone fixed this issue yet? If not, would try- catch be the right way to get around this error?

Has anyone fixed this issue yet? If not, would try- catch be the right way to get around this error?
This Cython issue is fixed in later Cython
If not, would try- catch be the right way to get around this error?
The right way to get around this error is to recreate glue code with Cython. The last message in the bug report says that:
http://sourceforge.net/p/cmusphinx/bugs/284/

Related

I keep getting an error when running my program in VS Code

I have recently started coding and I am using Pycharm and VS Code.
I encountered a problem and I cant seem to find any soloution to it, and I am to fresh to figure it out myself.
I run this simple program:
count = 0
for number in range(1, 10):
if number % 2 == 0:
count += 1
print(number)
print(f"We have {count} even numbers")
In Pycharm it works, but in VS Code it returns the error:
Traceback (most recent call last):
File "d:\Coding\HelloWorld\app.py", line 2, in <module>
from termios import CBAUDEX
ModuleNotFoundError: No module named 'termios'"
Does anyone one a clue what I need to do specifically?
The tutorial I am following is also using VS Code, and he doesn't seem to encounter the same issue.
I went in there and I had these three lines printed in the top of my file:
from distutils.cmd import Command
from termios import CBAUDEX
from tkinter import FIRST.
I removed them and now I dont get the error anymore!

"AttributeError: 'module' object has no attribute" - Can someone explain the meaning of this error message?

I'm trying to get the ODB library working. In the documentation at https://python-obd.readthedocs.io/en/latest/ it lists the following code:
import obd
connection = obd.OBD("/dev/ttyUSB0") # connects to USB or RF port
cmd = obd.commands.SPEED # select an OBD command (sensor)
response = connection.query(cmd) # send the command, and parse the response
print(response.value) # returns unit-bearing values thanks to Pint
print(response.value.to("mph")) # user-friendly unit conversions
When I put this in a file called test.py and I run it:
python2 test.py
I get the following error message:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import obd
File "/home/ubuntu/obd.py", line 3, in <module>
AttributeError: 'module' object has no attribute 'OBD'
Stackoverflow comes up with several iterations of this error message, but none clearly explain the problem, only giving specific solutions to those libraries.
I guess it's obvious that I'm new to Python, and I'm having trouble interpreting this error message, even after several hours of writing several small Python programs. I am of course also interested in why the error message is so un-intuitive to a newcomer and where I can gain the common knowledge I might be missing, and I guess this is as good a case to discover that through as any.
So far I have figured out the following:
<module> refers to the name of my python script that I am trying to run.
The mistake I made at first, was to name my test.py file, initially obd.py. This conflicted with the import obd as it was trying to import the file itself - even after I deleted it! The reason was that when I tried to run it the first time, it created a file called obd.pyc - and even though obd.py was no longer there, import OBD found the initially created obd.pyc and tried to import that - which of course does not contain the OBD object from the library I was trying to use.
This is not the detailed answer I'm looking for, so please add a more detailed explanation - or a link to how Python compiling works, if you can.

How to get the corresponding ctype for stdout on OS X using libc.dylib

I was following some of the answers in Python ctypes: Python file object <-> C FILE * and I have encountered a problem. The following code:
from ctypes import *
libc = CDLL('libc.so.6')
cstdout = c_void_p.in_dll(libc, 'stdout')
Works without errors on my virtual machine running Ubuntu. However when I try to do the same thing on my MacbookPro running HighSierra, i.e:
from ctypes import *
libc = CDLL('libc.dylib')
cstdout = c_void_p.in_dll(libc, 'stdout')
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
ValueError: dlsym(0x7fff6bfc4728, stdout): symbol not found
I tried this using python2.7 and python3.5. With both of them I get no errors on Ubuntu and the previously mentioned error on OS X HighSierra.
The reason why I need this is because I am coding a Python wrapper for a C api, and in that C api there is a function that expects FILE* as an input argument, so I want to pass stdout to it.
Any help would be appreciated!
p.s. I would like to apologise for writing a new post, instead of commenting in the existing one, but I am a new user with only 35 reputation at the moment and I am not allowed to comment until I get at least 50 reputation.
From the stdio.h header on macOS:
#define stdout __stdoutp
Therefore your python code should do this instead:
cstdout = c_void_p.in_dll(libc, '__stdoutp')
I hope that the answer was helpful.

Syntax Error in python Wifi Module

So I am trying to use python's wifi module to get neary wireless networks and log into them using a password. So far this is my code just to get the networks...
from wifi import Cell, Scheme
Cell.all('interfacename')
And I am receiving the following error...
Traceback (most recent call last):
File "python", line 1, in <module>
File "/goval_modules/python3.6/pbkdf2/__init__.py", line 69
print pbkdf2(p, s, l, i).encode('base64')
^
SyntaxError: invalid syntax
Can someone please help me understand why this error is appearing and how to fix it?
As Kanak mentioned, this WiFi module was written in python2, but you are using it in python3. Unfortunately, there is no workaround for this.
One possible fix could be trying to find an updated version of this module. You could also write your code in python2, but that might be a bit impractical.

Using osmviz in Python

I am trying to use the osmviz module of Python, which allows to use maps from OpenStreetMap.
So I downloaded it with pip, and then I tried to run one of the examples offered by the documentation page of osmviz (https://hugovk.github.io/osmviz/html/doc.html), the third one (https://hugovk.github.io/osmviz/html/pil_example.py.html).
However it doesn't work, I keep getting the following error :
Traceback (most recent call last):
File "testosm.py", line 1, in <module>
from osmviz.manager import PILImageManager, OSMManager
File "/home/FUNDP/mcohilis/.local/lib/python3.4/site-packages/osmviz/manager.py", line 60
raise Exception, "UNIMPLEMENTED"
^
SyntaxError: invalid syntax
So the error seems to be inside the module code and is a syntax error, which I find very weird. What could I do about it?
I get the same error with another code using osmviz, and I tried with two different computers, it doesn't change anything.
Does someone know how to use osmviz ?
Thanks a lot,
Marie

Categories

Resources