I'm trying to use Pygsr, what I'm doing wrong?
from pygsr import Pygsr
speech = Pygsr()
speech.record(3)
phrase, complete_response = speech.speech_to_text('es_ES')
print (phrase)
but I got error:
Traceback (most recent call last):
File "D:/VIV/PyCharm_project/0_WORKFILE_2.py", line 1, in <module>
from pygsr import Pygsr
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\pygsr\__init__.py", line 30
print "REC: "
^
SyntaxError: Missing parentheses in call to 'print'
Process finished with exit code 1
The issue is that the Pygsr library seems to be written with some version of Python 2 in mind.
In Python 2, print is a statement and as such allows "softspace" in between the statement itself and the string to be printed. As of Python 3.0, print is a function and as such, requires opening and closing parentheses around the function arguments. Because Pygsr is written with some version of Python 2, it still uses the statement form of print, which is invalid in Python 3. This can be seen in the line that the SyntaxError is pointing to, which is a statement and not a function (print "REC: " vs print("REC: ")).
You've got a few options for fixing this issue:
The first option is to switch back down to using the latest version of Python 2 (which is 2.7.11 at time of writing). This will mean that anything that's not backwards compatible in 3 (but still works in 2) will function, but I don't recommend switching versions just to get a library working, especially because it will affect the code you write. As well as that, the general consensus (to the best of my knowledge) seems to be that new scripts built on 2 should use the function form of print, which is available from 2.6 onwards but can be imported from __future__ for versions before 2.6.
The second option is to use the automatic tool 2to3 to convert the scripts in the library to be compatible with 3. This won't always work 100% due to the complexity and potential edge cases that a Python script may have, but it's usually a good way to get a lot of the simpler changes out of the way quickly.
The third option is to make the changes yourself. This should be as simple as manually going through the library and fixing any references to print, but you could also find the issues by running your script, seeing which file and line number is referenced in the error and then making the required edits.
Related
I'm currently updating a legacy application from Python 2.7.15 to Python 3.8.10. At the same time, I'm updating from wxPython version 2.8.12.1 to wxPython version 4.2.0.
I've used the 2to3 tool as well as done a lot of manual changes and the application is mostly running properly now. I have one major issue however, and it has to do with double-buffered drawing.
Specifically, in my onPaint() event handler, that has been bound to the EVT_PAINT event, I have the following code:
def onPaint(self,event):
drawPanelSize = self.drawPanel.GetSize()
self.bg_img = wx.Image('/background.png', wx.BITMAP_TYPE_ANY).Scale(drawPanelSize[0],
drawPanelSize[1])
bmp = wx.bitmap(self.bg_img)
dc = wx.BufferedPaintDC(self.drawPanel, bmp, wx.BUFFER_VIRTUAL_AREA)
There is more code above and below the code shown above, but this is the important area.
The problem that I am seeing is the following:
Traceback (most recent call last):
File "./TestBench.py", line 1553, in onPaint
dc = wx.BufferedPaintDC(self.drawPanel, bmp, wx.BUFFER_VIRTUAL_AREA)
wx._core.wxAssertionError: C++ assertion ""IsOk()"" failed at /tmp/pip-install-ewiqr929/wxPython/ext/wxWidgets/src/gtk/dc.cpp(238) in DoStretchBlit(): invalid DC
Does anyone have any insight into what may be going wrong here? Like I said this code worked fine using and older version of Python and an older version of wxPython. I would also accept any advice on how to appropriately debug this.
Please let me know if more information is required. I've already verified that the arguments to the function are valid. (i.e. self.drawPanel, and bmp are created properly and are valid arguments to the BufferedPaintDC method)
Also keep in mind most of the application (including the UI widgets, which are relying on gtk) is working at this point.
Things to note about my environment:
ubuntu (20:04)
gtk-3 (3.24.2)
Python (3.8.10)
wxPython (4.2.0)
I have been farting around with a music player project in Python and I have created a nested dictionary of {'album':{'tracks':{trackID:{length:00, title:'name', 'artist'}}}}
trackID and length are of type int and everything else is strings.
I am getting this error - TypeError: unhashable type: 'list'
I am using Visual Studio Code as my IDE. When I execute this code in one file window in (my main program), it doesn't work (gives me the above mentioned error), but then when I execute it in another window (from a test file), it works as expected. I am using the latest Python 3.7.4 and all my libraries are up to date. I'm also using Mac OS Mohave 10.14.6.
if trackID in musicDict["albumName"]["tracks"].keys()
print (str(trackID) + " found!")
I can't figure out why the result would be different from one file window to the other. I'm thinking there may be something somewhere else in the code causing this and it's not showing up as an error, maybe?
If you need more details, I will try to provide. I'm new to Python and this one has me stumped...
I ran my program in Python 3.4, and it crashed. Stack trace:
Traceback (most recent call last):
[...]
File [...], line 176, in manual_setup
gammas.add((name, group_oid))
KeyError: '5733455d-ba37-48c6-b550-8f53b719310c'
Here's the code at that line. Never mind what the variables are, just that gammas is a set, as you can see:
gammas = set()
for group_oid, name, _ in self.tags:
gammas.add((name, group_oid))
By the way, name and group_oid are both str, but even if they were something unhashable, I'd get a different error.
I'm not excluding the possibility that I have something totally different going on, but before I look into weird causes I haven't even thought of yet, I'd like to know if set.add could possibly be throwing KeyError. The documentation suggests no. My knowledge of how sets work says it shouldn't. Has anyone out there seen this happen?
I checked to see if set was somehow overridden. PyCharm says it's the built-in Python set.
The only set operations that generate a KeyError are pop on an empty set and remove for an element that isn't in the set. add can't generate a KeyError.
My first guess would be that this exception is coming from the __hash__ method of name or group_oid. Inspecting those objects in a debugger could be informative. There's also the possibility it's coming from an __eq__ method.
Somehow, the Python interpreter was outputting the wrong line number and accompanying code for the error. The error was a few lines above. I should've guessed... Maybe I changed the code while it was running (How can the line numbers in my stack traces be wrong?), but I don't think I did. Anyway, it's not happening anymore.
P.S. I didn't immediately re-run and catch it because the script takes a long time to reach that point again.
I am new to python, trying to automate powerpoint using win32com. I am unable to import or use constants in my scripts. I have ran makepy to create libraries. below is the error messages & script. Can someone tell me how to import constants ?
Script :
import win32com.client
Application =win32com.client.gencache.EnsureDispatch("PowerPoint.Application")
Presentation = Application.Presentations.Add()
Base = Presentation.Slides.Add(1, ppLayoutBlank)
Error messages :
Traceback (most recent call last):
File "ppt.py", line 14, in
Base = Presentation.Slides.Add(1, ppLayoutBlank)
NameError: name 'ppLayoutBlank' is not defined
The INTEROP method you have chosen depends on the application interface to which you are connecting.
Not defined usually means that there is no such variable, but Python more often raises NameError in such cases. So what is exactly happening here is a little unclear.
So, depends on the version of PPoint on how to communicate with it.
I advise you to use pywinauto instead and go for "brute_force", i.e. emulate key presses and/or clicks etc. on right buttons, menues etc.
Because the names of thous is little less likely to change trough out the versions than a COM interface.
Microsoft has a nasty habit of changing just a little bit the interface, and then a program stops working.
If you want to insist on win32com, you will have to read PPoint's documentation for a specific version (or Office version), and for win32com for your Python version.
You should see whether you should start a COM Client or is there some other MS tweak you need to employ.
I'm under Linux now and cannot test here, but try to
import win32com.client.constants
... and then look for the constants defined in that module.
See also How to use win32com.client.constants with MS Word?.
I'm new to this, so I'll try to explain clearly.
I'm using Octave (4.x) to process data and I want to import an Excel file. Excel is installed on my laptop as well.
[num,txt,raw] = xlsread(input.rootdir);
When the function is called, the following message appears:
warning: Functions for spreadsheet style I/O (.xls .xlsx .sxc .ods .dbf .wk1
etc.) are provided in the io package. See <http://octave.sf.net/io/>.
Please read <http://www.octave.org/missing.html> to learn how you can
contribute missing functionality.
warning: called from
__unimplemented__ at line 524 column 5
CreateInvoices at line 18 column 3
error: 'xlsread' undefined near line 18 column 5
error: called from
CreateInvoices at line 18 column 3
>>
The warning appears that the I/O package is not installed. However, the package is listed when I call 'pkg list' in command line, so it seems to be installed correctly.
pkg list
There are some other topics on stack overflow with a similar content, but they seem to be solved with proper installation of the I/O package.
If I try to call 'pkg load io', Octave crashes immediately.
I tried to use other functions to import data (csv, textread, ...), but I always lose my text data. So that is not really helpful.
Does anyone have some advice for me?
Thanks in advance for the reply!
Best regards,
Lode
I've just done this, but in Linux (Xterm windows with bash). I had to install liboctave-dev package first, then the io octave package. Then the call to 'pkg load io' before using it. But need to make sure to install with root privileges or the package won't be found by a shared Octave installation. Of course, this was not on windows but might provide some clues.