I'm pretty new to Qt, Python and their combinations. I'm currently writing a QGIS plugin in python (I used QtCreator 2.1 (Qt Designer 4.7) to generate a .ui-file and am now trying to use it for a Quantum GIS plugin that's written in Python 2.5 (and running in the Quantum GIS Python 2.5 console)).
I am running into trouble when loading the ui-file dynamically when the program runs the loadUi() function. What throws me off is that the error occurs outside my script. Does that mean, I'm passing something wrong into it? Where does the error come in? Any hints on what could be wrong?
code_dir = os.path.dirname(os.path.abspath(__file__))
self.ui = loadUi(os.path.join(code_dir, "Ui_myfile.ui"), self)
This is the Error Code I am getting (minus the first paragraph):
File "C:/Dokumente und Einstellungen/name.name/.qgis/python/plugins\myfile\myfile_gui.py", line 42, in __ init __
self.ui = loadUi(os.path.join(code_dir, "Ui_myfile.ui"), self)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic__init__.py", line 112, in loadUi
return DynamicUILoader().loadUi(uifile, baseinstance)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\Loader\loader.py", line 21, in loadUi
return self.parse(filename)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 768, in parse
actor(elem)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 616, in createUserInterface
self.traverseWidgetTree(elem)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 594, in traverseWidgetTree
handler(self, child)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 233, in createWidget
topwidget.setCentralWidget(widget)
SystemError: error return without exception set
I'm not sure of what could be causing this precise problem, but using .ui files directly has never worked well for me - instead I compile them to python code using pyuic4 (should be in your path if your PyQt4 site-packages are correctly configured. The syntax is along the lines of :-
pyuic4 -o <python output> -x <uic input>
-: resource files can similarly be converted to (not so human-readable) python using :-
pyrrc4 -o <python output> <qrc input>
-: You can then import that python file as a module, not to mention that reading its code can give you clues on how to fiddle with the layout at runtime.
The other upside of this is that you are not having to parse xml at runtime - importing a python module is far quicker and you are not likely to change the ui anywhere near as often as you run the script. If you do find yourself in this situation you can just create a batch to run these before your script/application.
This is the method I use in conjunction with pyInstaller to deploy scripts that will 'just run' on XP, Vista and Windows 7 without modification, and I generate the python modules just before compiling with pyInstaller, so it can be a real time saver.
Related
I know that questions have already been raised on this topic, but I believe that all decisions were strictly individual. The essence of the problem:
There is a calculator.py script and a kalkulator.py These files are in the same directory, the calculator file is executable, this is the file that I convert into an EXE using PyInstaller. Inside the file, I import several PyQt5 libraries, and the second file is Python: from kalkulator import *
The second file kalkulator.py contains the GUI of the program created with QtDesigner
When i run the command pyinstaller --onefile --debug calculator.py everything goes fine.
But when I run the EXE program file in debug mode, I see the following error:
The photo shows that the following error occurs.
"DLL Load Failed: The specified procedure could not be found."
I can assume that the problem is that when assembling, PyInstaller does not see the file kalkulator.py it contains a graphical interface.
What can you say about this problem, how do you think you can solve it?
I use:
Python 3.5
PyQt5
PyInstaller 3.3.1
I managed to solve my problem! I changed the version of Python 3.5.0 to 3.6.0, and also reinstalled PyQt5.
I understand this question has been asked multiple times and answered in different forums but it looks like there are variants of the issue and mine is probably, slightly different.
Let me explain. I am trying to call a octave function which I had written for plotting and I don't want to re-write it again python. Therefore I did the following:-
1. install the oct2py
2. setup the OCTAVE_EXECUTABLE= c:\Octave\Octave-4.2.1\bin\octave-gui.exe
3. did the following in the code:-
#importing oct2py
from oct2py import octave as oc
oc.addpath("C:\\personal\\learning\\octave-lib") #containing my octave .m files
#Now I am trying to call a plot function written in octave called displayData.m
oc.displayData(X) # where X is a numpy matrix for plotting
However on executing call to the method gives no errors - but it does not do anything. I see a windows shell prompt opening & closing but nothing else.
I have also tried to replace octave-gui-4.2.1.exe with octave-cli-4.2.1.exe following the suggesting from some sites but I was getting errors that bulk of the windows dll required were not found.
I started with the advice from the oct2py site asking me to just add the path to the folder containing octave.exe ( note that this folder contains all the octave executable) , but that resulted in windows permission errors. There should not be any reason for this error since I am the only user on my windows laptop and have administrative privileges. I am getting the following errors:-
File "mcclassifier.py", line 21, in <module>
from oct2py import octave as oc
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\__init__.py", line
38, in <module>
octave = Oct2Py()
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\core.py", line 73,
in __init__self.restart()
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\core.py", line 508, in restart logger=self.logger)
File "C:\Users\Sam\Anaconda3\lib\site-packages\octave_kernel\kernel.py",
line 144, in __init__
self.repl = self._create_repl()
File "C:\Users\Sam\Anaconda3\lib\site-packages\octave_kernel\kernel.py",
line 338, in _create_repl
version = subprocess.check_output(version_cmd).decode('utf-8')
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 990, in
_execute_child startupinfo)
PermissionError: [WinError 5] Access is denied
I tried to run it from Spyder IDE and also from the command line. Both have the identical behavior. Its been frustrating , so any suggestion to get me past this issue will be a big help !!
ADDITIONAL INFORMATION:-
Probably I was not very clear above, but what I am trying to do is to execute a plotting function which i had implemented in octave, & is working.
I made some changes to my python code to see if I can instantiate the Oct2Py class and then call feval function. I commented the previous lines of code above and added the following:-
octave=oct2py.Oct2Py()
octave.feval('C:\\personal\\learning\\octave-lib\displayData',Xmat,timeout=80)
I can see from the windows taskbar that octave-gui.exe being invoked and is seen as running in the background. But it is still not plotting and there is no error.
How do I make it run as foreground process and render the plot. What I want to do is similar to what is shown in the oct2py demo example at:-
http://blink1073.github.io/oct2py/source/demo.html.
As you can see that oc.plot([1,2,3],...) renders the plot.
I will greatly appreciate any help here ?
I am trying to convert python code to a windows .exe using cx_freeze. When I run the setup.py using the command line it runs as usual and then just returns invalid syntax. The program uses the tkinter module as well as sympy and I believe it is the latter causing the problem. Any solutions will be much appreciated. Below is the last part of the process before it stops.
deferredImports, namespace = namespace)
File "C:\Python33\lib\site-packages\cx_Freeze\finder.py", line 338, in _Intern
alImportModule
parentModule, namespace)
File "C:\Python33\lib\site-packages\cx_Freeze\finder.py", line 366, in _LoadMo
dule
module.code = compile(codeString, path, "exec")
File "C:\Python33\lib\site-packages\sympy\mpmath\libmp\exec_py2.py", line 2
exec string in globals, locals
^
SyntaxError: invalid syntax
The compatibility for exec in SymPy (actually mpmath, which is included with SymPy) uses a file that is only run in Python 2 that is invalid syntax in Python 3 and a file that is only run in Python 3 that is invalid syntax in Python 2. You can safely ignore the one on the other. If cx_freeze refuses to skip this file, you can safely delete it.
I am attempting to develop a component for 64 bit Redhawk that uses a 32 bit Python binary, but am not sure how to configure Redhawk use 32 bit Python instead of 64 bit Python when running this particular component. The reason I need to use 32 bit Python is because I am using a library (PyVisa, http://pyvisa.readthedocs.org/en/latest/) that only works with 32 bit Python (see https://decibel.ni.com/content/docs/DOC-2928).
I am using PyVisa to control lab equipment (i.e. Agilent signal generators) in order to a calibrate a receiver. I understand this may seem like a odd use of Redhawk, but tuning sig gens to a certain freq and power level is very similar to operations that need to be performed when controlling a receiver/transmitter as well.
I would rather not install 32 bit CentOS just to develop and test this 1 component and I'm assuming it will be equally troublesome to simultaneously install 32 bit and 64 bit Redhawk rpms on my system.
I have already installed 32 bit Python simultaneously with 64 bit Python on my system and have manually renamed the 32 bit Python binary to be "python_32" and placed it on the path (/usr/bin/). I tried to force Redhawk to use the 32 bit Python executable by changing the shebang at the top of my implementation file to
#!/usr/bin/env python_32
However, it didn't work, so then I tried
#!/usr/bin/python_32
which also didn't work.
See example below for a skeleton implementation, with all the boilerplate imports and function defs removed for clarity.
#!/usr/bin/python_32
import visa
def process(self):
sg = visa.instrument("TCPIP::10.2.8.236")
print sg.ask("*IDN?")
return NORMAL
Each time I attempt to launch a simple waveform containing this component, I receive the error below. This is the same error I receive when trying to use the PyVisa libary in 64 bit Python, which is why I think Redhawk is ignoring my shebang statements specifying the path to 32 bit Python.
OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: wrong ELF class: ELFCLASS32
Traceback (most recent call last):
File "/var/redhawk/sdr/dev/.DevMgr_orion/GPP_orion/components/sendSCPI/python/sendSCPI.py", line 9, in <module>
import visa
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/visa.py", line 237, in <module>
resource_manager = ResourceManager()
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/vpp43.py", line 85, in __new__
it.init(*args, **kwds)
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/visa.py", line 230, in init
self.session = self.vi = vpp43.open_default_resource_manager()
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/vpp43.py", line 788, in open_default_resource_manager
visa_library().viOpenDefaultRM(byref(session))
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/vpp43.py", line 162, in __call__
self.load_library()
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/vpp43.py", line 131, in load_library
self.__lib = self.__cdecl_lib = cdll.LoadLibrary(path)
File "/usr/lib64/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib64/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: wrong ELF class: ELFCLASS32
For reference I am running Redhawk version 1.9.0. x64 on CentOS 6.4 x64.
If there is a better way to control my lab equipment through Redhawk, I'm open to that too.
The <entrypoint> in the component.spd.xml file can be changed to point to a script instead of the component's .py file. This is useful for doing things like setting environment variables for a single component or redirecting to a different program.
Consider this:
Change <entrypoint>python/myComponent.py</entrypoint> to <entrypoint>python/myScript.sh</entrypoint>
Create a script called myScript.sh in the python folder.
Populate myScript.sh with something like:
export PYTHONPATH=$PYTHONPATH # add/change PYTHONPATH (or other environment variables) here
/usr/bin/python_32 python/myComponent.py $*
chmod +x myScript.sh
Modify your autotools files so that the script gets installed correctly (or just copy it by hand)
This approach gives you a little more control over how myComponent.py gets run.
I want to try Mako with Django instead of Django's default template language. But I'm having a problem when I try to import Mako's Template class as written in the manual:
from mako.template import Template
mytemplate = Template("hello world!")
print mytemplate.render()
I do this in Windows cmd and receive such an error:
C:\Documents and Settings\User>cd C:\py\project\vendor\template\Mako_73 // cd to where I unpacked Mako
C:\py\project\vendor\template\Mako_73>python // run Python interpreter
>>> from mako.template import Template // trying to import and getting an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".\mako\template.py", line 622
exec code in module.__dict__, module.__dict__
^
SyntaxError: invalid syntax
The code from that part:
def _compile_text(template, text, filename):
identifier = template.module_id
source, lexer = _compile(template, text, filename,
generate_magic_comment=template.disable_unicode)
cid = identifier
if not util.py3k and isinstance(cid, unicode):
cid = cid.encode()
module = types.ModuleType(cid)
code = compile(source, cid, 'exec')
exec code in module.__dict__, module.__dict__
return (source, module)
What can it be? I couldn't find anything in Google about this error.
I'm using Python 3.3.
I've downloaded Mako-0.7.3 as tar.gz file and just unzipped it in
C:\py\poject\vendor\template\Mako_73. I do not have this directory in the PYTHONPATH or paths.pth. C:\py\poject is a directory where my Django project lives and in \vendor\template I've decided to put Mako and import it from there.
UPD
I found the solution. I've installed the Pyramid Framework and have taken the Mako from there as the Mako is a default template system in it. And Pyramid's version works fine.
Your basic problem is that you are using Python 3, which is relatively new for large projects like Django.
Secondly, you need to find out how to install packages correctly. I don't know where you got Mako from, but you won't find anywhere that says "just unpack the tarball" - perhaps you are assuming that from your knowledge of PHP, but it's not correct.
On the Mako site, the suggested method of installation is pip.
If you go for downloading manually, you need to read instructions about installing Python packages, for example here: http://wiki.python.org/moin/CheeseShopTutorial
The reason Mako doesn't work for you is that the installation procedure (which you haven't run) converts all the provided Python 2 code so that it works on Python 3. It is not that someone didn't bother to check the code for basic syntax errors!
If you are trying to use Django, though, Python 3 is definitely the wrong choice - the installation instructions clearly say you need to be using Python 2.5 to 2.7: https://docs.djangoproject.com/en/1.4/intro/install/
Since you are new to Python, you should try to walk before you run, and go with the tried and tested path - which is Python 2.7 for Django. Ignoring installation instructions and requirements will only slow you down and make life hard.