I've been trying to get PyQt4 to work on my OSx machine (10.8.5) for some time - I've loaded it on my windows machine with no problem by using an installer.
I have sip 4.8.5, Python 2.7 Qt 4.8.5 loaded on my machine using homebrew.
When I try to debug the following file in WING, I get the following error:
Code from Zetcode as a test
import sys
import QtGui
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Exception:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/PyQt4/_qt.so, 2):
Library not loaded: QtDesigner.framework/Versions/4/QtDesigner
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/PyQt4/_qt.so
Reason: image not found
Why is the Qt library not loading? What do I need to do to get the library to load?
Thanks,
-j
I don't personally use homebrew, but I'm pretty sure it installs stuff in /usr/local. From the error message it looks like it is accessing /Library/Frameworks/Python.framework. I also don't use WingIDE, but it looks like it is using a different python install than you want it to. I'm sure there is a way to specify which python it uses.
You probably need to set the Python Executable in Project Properties (from the Project menu) to /usr/local/bin/python -- or whatever the value of sys.executable is in the Python that has PyQt4 installed into it.
Note that in Wing 101 this is done in the Configure Python dialog instead, which is accessed from the Edit menu.
Related
I have some experience with Python console applications and now trying to start with Qt for Python (Qt 5.12, PySide2). Actually I'm trying some basic tutorials to understand how it should work.
So, I created very simple view.qml:
import QtQuick 2.0
import QtQuick.Controls 2.13
ApplicationWindow {
visible: true
Button {
id: button
text: qsTr("ClickOnMe")
}
Connections {
target: button
onClicked: con.say_hello()
}
}
and have following python code to work with it:
from PySide2.QtCore import QObject, Slot
from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine
class Bridge(QObject):
#Slot()
def say_hello(context):
print("Button clicked, Hello!", context)
app = QGuiApplication([])
engine = QQmlApplicationEngine()
bridge = Bridge()
context = engine.rootContext()
context.setContextProperty("con", bridge)
engine.load("view.qml")
engine.rootObjects()
exit(app.exec_())
It works fine when I simly run it - i.e. I see an application window with a button. I may click a button and see message printed in console.
But when I try to debug it - it stops immediately on line class Bridge(QObject): with following exception:
<class 'tuple'>: (<class 'TypeError'>, TypeError("'Shiboken.ObjectType' object is not iterable"), <traceback object at 0x7fe195b23680>)
I tryied the same in Qt Creator - works fine, not problems with Run and Debug (the minor issue - messages in Qt Creator console appear only after application termination). But I like PyCharm more so would like to understand how I may fix this problem and continue to use PyCharm with Qt.
If it's important - I'm running ArchLinux.
A few days ago Arch Linux updated its version of Python to 3.8 but PySide2 does not yet have a compatible version causing the error you are pointing out. As they point out in this report PYSIDE-1140:
I'm keeping this open, but it will probably be solved for 5.14, since
then Python 3.8 will be introduced as a new compatible Python version.
So you have 2 options:
Wait for a release of PySide2 that is compatible with Python3.8.
Or install Python3.7 or an old version from aur (using yay) and then install PySide2 using pip.
This was actually a bug in Qt for Python using Python 3.8, however it is already been solved here.
Just update your qt:
pip install PyQt5
I researched and tried this for two days now and I cannot get gtk to work on Windows 7 with Python 3.4! Whenever I launch my .py file on Python 3.4 with import gtk, I get No module named gtk! I installed pygobject but it did not help. Even gtk3-demo command works in the windows cmd prompt.
I finally got gtk to import (I think) by copying the GTK directory right to C:\Python34\Lib. But now I have a problem with gtk.glade.
Where is this? Where do I copy it from and to where?
You are possibly using an outdated tutorial, see the current Python GTK 3 tutorial for a more up-to-date reference.
In particular, the way to import GTK has changed in GTK3 to:
from gi.repository import Gtk
And instead of libglade, you would use the newer Gtk.Builder class like so:
ui = Gtk.Builder()
ui.add_from_file("my_glade_file.glade")
(you still develop the UI using Glade, it is only how you access it from your program that has changed).
Edit: I had to change the question because I found that the problem related not only to ODBC driver bu to all drivers such as MYSQL, SQLITE etc.
So the problem is this: I try to connect to a database using PySide and QtSql module.
The critical snippet:
from PySide import QtGui
from PySide import QtSql
import sys
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
db = QtSql.QSqlDatabase.addDatabase('QODBC')
# or others: QMYSQL, QSQLITE etc.
sys.exit(app.exec_())
and when I try to run it, I get a message:
QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers:
When I try equivalent PyQt4 instead of PySide, I get no message which I assume means that the ODBC driver is available with PyQt4. However, unfortunately, I cannot switch my application from PySide to PyQt4 for many other reasons.
When I look into Python Lib folder I can see that python-3.3.2\Lib\site-packages\PySide\plugins\sqldrivers contains DLLs including qsqlodbc4.dll. So there is something more missing and I do not know what.
As I wrote the problem is not just with ODBC but with all database drivers.
Found a solution here on stackoverflow here (relates to PyQt rather than PySide but it works): PyQT can't find any SQL drivers
In short - put this code before calling addDatabase:
site_pack_path = site.getsitepackages()[1]
QtGui.QApplication.addLibraryPath('{0}\\PySide\\plugins'.format(site_pack_path))
If you encounter a similar issue using modern PySide6, here is the full answer:
https://stackoverflow.com/a/72169911/211369
One of solutions is to define the QT_PLUGIN_PATH environment variable, so that it contains the "sqldrivers" sub-directory with SQL plugins for Qt platform.
In your example, QT_PLUGIN_PATH=c:/python-3.3.2/Lib/site-packages/PySide/plugins
BTW almost a half of info known to me is is officially published at https://doc.qt.io/qt-6/deployment-plugins.html
I have a python program:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import *
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("htpp://www.google.com"))
web.show()
web.resize(650, 750)
web.setWindowTitle('Website')
sys.exit(app.exec_())
I used google.com just for example. But if i want to make an executable of this program with py2exe but it wont work. I get this error:
With other programs without PySide it does work. But with PySide it doesnt. How can I make it work?
You need Microsoft Visual C runtime.
You should take a look at this: http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows . In the py2exe tutorial it explains about the runtime you should install.
You are missing a DLL. The DLL in question can be (at least formerly) obtained from Microsoft by downloading their free compiler package.
Alternatively, ensure that this process has the right paths set to find the DLL in question.
I was trying to do gui programming in Python.I figured out that PySide is a good framework to start with.As i was running Python 2.7.2 i downloaded PySide 2.7 and tried running a sample app.I got QtCore Library not loaded error.
This is the error that i got..
from PySide import QtCore, QtGui
ImportError: dlopen(/Library/Python/2.7/site-packages/PySide/QtCore.so, 2):
Library not loaded: QtCore.framework/Versions/4/QtCore
Referenced from: /Library/Python/2.7/site-packages/PySide/QtCore.so
Reason: image not found
I googled and found out that many people were facing the same issue and i saw solutions being posted based on exporting DYLD_FRAMEWORK_PATH. I was not able to follow this.
Could anyone please tell me whats the issue and how to fix it!!
Thanks..
You don't mention the OS you are working on, but from the paths in your error message it looks like you're on Mac OSX.
I'm not an expert in PySide at all, but I had the same problem a while ago and I think I know what's going on: The library at /Library/Python/2.7/site-packages/PySide/QtCore.so is the part that makes the Qt Core C++ library available to Python. It is just the wrapper though or some sort of translator between C++ and Python, the actual C++ functionality is elsewhere - and when the Python interpreter tries to load the C++ library that contains that functionality from QtCore.framework/Versions/4/QtCore, if fails to find it, hence the error message.
A quick and dirty way to solve your problem is to create symbolic links from the location where QtCore.so expects the C++ library to where it actually is. For that, you will obviously have to find the C++ library. If you downloaded Qt 4.8.4 as an installer from the Qt Project page, the libraries AFAIK are somewhere in /usr/lib, so you would create a symlink like this:
ln -vis /usr/lib/<insert subfolder>/QtCore.framework /Library/Python/2.7/site-packages/PySide/QtCore.framework
You will have to do this in a similar way for QtGui and any other Qt library you want to use as well. Note that this obviously does not symlink the library itself, but the folder in which QtCore.so expects it.
An alternate way would be to build PySide from the sources (which is what I ended up doing), but that takes longer - and you sound like you just want to get going with Python and Qt.
Have you installed standalone QT package for mac?
Qt for Mac OS X: Download Qt 4.7.4 ftp://ftp.qt-project.org/qt/source/qt-mac-opensource-4.7.4.dmg standalone pyside installation raises same error log for me