Can't import wx (wxPython Phoenix) into my script - python-2.7

I'm taking a course in Python, and the current assignment is to convert a previous assignment written in Python 2 (which used wxPython) to Python 3 (which needs Phoenix). I successfully installed Phoenix, and in the Py3 shell I can now import wx just fine. However, if I try to run my actually script, it immediately gets this error:
Traceback (most recent call last):
File "C:\Python27\transferdrillPy3.py", line 10, in
class windowClass(wx.Frame):
NameError: name 'wx' is not defined
What's up with that?

I tried going through my code and deleting every single "wx.", and now it works. I guess Phoenix doesn't need that.

Related

unable to call glCreate* in pyOpenGL

I'm running a code using pyopengl and have some problems of calling glCreate* functions.
The code is running in ubuntu 16.04, python2.7 and the pyopengl version is PyOpenGL 3.1.3b2 and PyOpenGL-accelerate 3.1.3b2 (already the latest versions).
It has the flowing problems:
when I try to call
>>> glCreateTextures
OpenGL.platform.baseplatform.glCreateTextures object at 0x7f16de11a050
It seems that the updated version of pyopengl does add this function (or class) but it's creepy that if I try to give it values for initializing:
>>> glCreateTextures(None,None,None)
Traceback (most recent call last):
File "", line 1, in
File "/media/sinnis/ADDDISK/pyopengl/OpenGL/latebind.py", line 41, in call
return self._finalCall( *args, **named )
File "/media/sinnis/ADDDISK/pyopengl/OpenGL/wrapper.py", line 689, in wrapperCall
result = wrappedOperation( *cArguments )
File "/media/sinnis/ADDDISK/pyopengl/OpenGL/platform/baseplatform.py", line 414, in call
self.name, self.name,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glCreateTextures, check for bool(glCreateTextures) before calling
It seems that the it is checking and considering this call an undefined function. That's how it raises problem in the script texture.py and I find that any glCreate* calls has this problem.
Still no solution to fix this problem. Help!

Name 'ftplib' is not defined?

Hey guys I've been cleaning up my old code, and I somehow have problems with declaration of ftplib in except block.
Traceback (most recent call last):
File "PiFtp2.py", line 57, in <module>
except ftplib.all_errors:
NameError: name 'ftplib' is not defined
Here is the Code (the entire code because I have no idea where the problem is):
Link to GitHub
PS: I'd appreciate if someone could tell me how to show code properly on stackoverflow as well :)
In the beginning of the file you imported only the ftp function from ftplib.
Instead of
from ftplib import FTP
use
import ftplib
and then change all FTP function calls from FTP(...) to ftplib.FTP(...) (line 51)

PiCamera cannot be initialized as a class member when the script is run from command prompt

on my Raspberry Pi, I encounter a strange behaviour regarding the use of the PiCamera module.
The following code runs smoothly when either started from IDLE (F5) or from the command prompt ($python test.py)
import picamera
if __name__ == "__main__":
camera=picamera.PiCamera()
camera.close()
But when I put the camera object into a class the code will run only when started from IDLE (F5):
import picamera
class VF:
def __init__(self):
self.camera = picamera.PiCamera()
def __del__(self):
self.camera.close()
if __name__ == "__main__":
myvf = VF()
When I start the above code from the command prompt, I get the following error message:
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
Traceback (most recent call last): File "test.py", line 14, in
myvf = VF()
File "test.py", line 6, in init
self.camera = picamera.PiCamera()
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line
379, in init
camera_num, self.STEREO_MODES[stereo_mode], stereo_decimate)
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line
505, in _init_camera
prefix="Camera component couldn't be enabled")
File "/usr/lib/python2.7/dist-packages/picamera/exc.py", line 133,
in mmal_check
raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Camera component couldn't be enabled:
Out of resources (other than memory)
The camera module is working correct, I just stripped the code down to the least possible size. Does anybody know this problem, or a similar problem, and can probably provide a solution? The Python Version is 2.7 and the Raspberry Rasbiab-System is completely up to date.
Thanks in advance.
I struggled with this one for hours, and kept getting the "out of resources" error. I finally figured out that in my take-the-picture function, I needed to make sure I did it like this:
camera = PiCamera()
(...camera settings here...)
camera.capture(myfileName)
camera.close()
If I didn't do the close(), I'd get that error every time.
So make sure that camera.close() is getting called right after the 'snap'. It solved the problem for me.
Found out, that the camera-module is not properly shut down when the destructor is not explicitly called (had LED turned off, so didn't see this).
IDLE handles a running camera by somehow resetting it before the script starts, but not the python interpreter.
So everything is ok now when the destructor is called before the script ends.

How can I load and execute python script in C++ application

I want to extend my application, which is written in C++ using python scripts (extensions). I originally wanted to use TCL for that, just like they do in xchat, for example, but later I decided to use python, because it seems to be quite popular for whatever reasons.
However, I am failing to load and execute even very simple python script. I followed http://docs.python.org/2/extending/embedding.html
When I give a filename of script that I want to load as argument to pName, the error I get from PyErr_Print is: ImportError: Import by filename is not supported.
Reading the documentation, I figured I might need to run PyImport_ExecCodeModule, however this C function requires 2 arguments, 1 is char * (probably a name of module), other one is compiled python code, which according to docs I can get by calling python function compile(). Unfortunately it doesn't say how do I call this python function using C api's in my C++ code. Ideally I would imagine to do something like
PyObject *code = PyCompile("print (\"hello :)\"");
but I couldn't find any function like PyCompile, neither any other C-api function that would simply allowed me to execute python internal function (like compile) and grab its output as PyObject.
So, question is: how can I easily load a python script from a file (something.py) and execute it within my application using the embedded python interpretor?

definition of qwtplot

it's my first post, hope to not break something :).
On windows there are two versions of python2.7, 32 bit and 64 bit both with pyqt and qwt5
i'm trying pyqt from some week, today i tried to use my python/pyqt/pyqwt code written on linux, on windows, but the prompt says:
C:\Users\bomba\Desktop\conversione_python\guibms>python-32 interfaccia_mark3.2.p
y
Traceback (most recent call last):
File "interfaccia_mark3.2.py", line 14, in <module>
from PyQt4.Qwt5.qplt import *
File "C:\Python27-32bit\lib\site-packages\PyQt4\Qwt5\qplt.py", line 95, in <mo
dule>
Y1 = Left = QwtPlot.yLeft
NameError: name 'QwtPlot' is not defined
someone could explain me this?
I would really apppreciate
You haven't defined the Qwtplot object.
Try using:
import PyQt4.Qwt5 as Qwt
plot = Qwt.QwtPlot()
and then use the plot object as you wish.