Errors importing other modules in monkeyrunner - monkeyrunner

I'm trying to import PIL with monkeyrunner
import re
import math
import os
from PIL import Image
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import commands
import sys
but I keep getting an error:
ImportError: No module named PIL
I know it is something with monkeyrunner because I can successfully import PIL when running a regular python script. I was reading around and maybe this had something to do with PYTHONPATH? I am not sure what I need to do to allow these other module imports with monkeyrunner.
I am running on windows.

You should install PIL for Python 2.5 under '/Library/Python/2.5/site-packages/'. Because MonkeyRunner uses Jython 2.5, based on Python 2.5.
Then add the path of PIL to Jython's path.
import sys
sys.path.append('/Library/Python/2.5/site-packages/your-PIL')
See How I install various Python libraries in Jython? for details.

Related

QML QtGraphicalEffects is not Installed

I am trying to build any random QML component, and having this line import QtGraphicalEffects 1.15 will cause an error: 'module "QtGraphicalEffects" is not installed`
I am running on a virtual machine and just created a new virtual environment with Pyside6 and Python using pip install PySide6==6.1.2 to get the latest version. I can find the folder GraphicalEffects with a qtgraphicaleffectsplugin.dll in the Qt5Compat folder of the PySide6 Lib so I do not know why it cannot import this module. The other ones like QtQuick.Controls import fine.
I have also used print("Qt version: " + str(QtCore.qVersion())) to double check Qt version, and I get Qt version: 6.1.2
There seems to be some solutions in other discussion posts, but I have not found one that refers to Python side of things. I am aware Qt 6.0 does not seem to have QtGraphicalEffects, but it's supposed to be in 6.1. I am also not sure if this has to do with the virtual machine because on host I actually have no issue using QtGraphicalEffects
Qt QtGraphicalEffects is available in PySide6 but the module has changed the way of importing to import Qt5Compat.GraphicalEffects as indicated in the docs.

Can't import Qt for Python in Maya

I am trying to build a small UI in Maya with QT through Python.
When I use:
from Qt import QtCore
In the script editor, it throws the following error:
Error: ImportError: file line 2: No module named Qt #
I am just starting out to explore this subject. Does this mean Qt isn't installed ? Is it not a part of the default package of Maya 2018 and 2019 ?
Any pointers as to why this may happen will be really helpful.

Error:: QtQuick packages are not installed

I am trying to execute the canvas3d project on qnx platform. While execution it throws an error as below
qrc:/main.qml:40:1: module "QtQuick.Layouts" is not installed
qrc:/main.qml:39:1: module "QtQuick.Controls" is not installed
qrc:/main.qml:38:1: module "QtCanvas3D" is not installed
main.qml has imported below
import QtQuick 2.0
import QtCanvas3D 1.0
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
Can anyone help me to figure out how can I install this missing modules?
I am using Qt Creator 3.5.1(enterprise) licensed version.
Thanks in advance.
I was able to resolve this error by using env variable QML2_IMPORT_PATH.
But Now I am getting an error qrc:/main.qml:37:1: module "QtCanvas3D" plugin "qtcanvas3d" not found
Can some one please let me know what can be done for this?
sudo apt install qml-module-qtquick-controls
sudo apt install qml-module-qtquick-layouts
etc.

graph_tool pyside gtk 2.x and gtk 3.x

Environment: openSuSE 12.3 - Gnome
Error:
When I execute my program, i get this:
"Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
Trace/breakpoint trap"
Notice:
It occurs whenever I try to import at the same PySide and graph_tool modules.
To be more specific, whenever I import draw from graph_tool (which is the one that probably uses GTK+ 3.x)
graph_tool: http://graph-tool.skewed.de/
Problem:
I NEED the draw function AND PySide modules
So:
Is there a way to force PySide to use GTK+ 3.x styles instead of 2.x ones?
Or any other option to use both modules harmonically?
Thanks in advance!
Just solved:
from PySide import *
import gtk
import graph_tool.all as gt
By importing gtk itself, it apparently overrides any attempt from PySide submodules to use GTK+ 2.x namespaces.
Must be imported BEFORE graph_tool, apparently.

PyQt5 and QtGui module not found

Is there some reason that QtGui is packaged with PyQt5???
I am using Mark Summerfield's Rapid GUI programming book. Obviously this book was written with Qt4 in mind, but I have been recommended to use Qt5, and PyQt5. I want to run the first example code in chapter 4. The code begins with the following import statements:
import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
To which the compiler responds:
Traceback (most recent call last):
File "wakeUp.py", line 4, in <module>
from PyQt5.QtGui import *
ImportError: No module named 'PyQt5.QtGui'
Note that the PyQt5.QtCore import statement does not generate an error.
From the terminal,
$ echo $PYTHONPATH
:/usr/lib/python3.3/site-packages
Has anybody else come across this import error for QtGui?
From an interactive session I can
>>> import PyQt5.Qt
>>> import PyQt5.QtDBus
>>> import PyQt5.QtNetwork
>>> import PyQt5.QtXmlPatterns
But I don't have QtWidgets, QtGui, QtWebkit, QtDesigner, and several others.
Also, if it is helpful, the contents of /usr/lib/python3.3/site-packages/PyQt5 are:
__init__.py QtCore.so QtDBus.so QtNetwork.so Qt.so QtXmlPatterns.so uic
which are the same modules that I am able to import. Should the other modules (QtWidgets, QtGui etc) be here too?
I am using Ubuntu 13.04 and Python 3.3.
When first trying pyqt4 and pyqt5 and the pycharm IDE I had many problems with imports. (although the imports had no prob running from IDLE) Eventually after much stuffing around, uninstalling and reinstalling, (including dependencies) the imports sorted themselves out.
Did you install pyqt5 using an installer from the pyqt website? You must.
Qt designer is found under the start menu in windows.
When following PyQt4 tutorials, I have had luck using the following import statements for PyQt5...
from PyQt4 import QtCore, QtGui #in the pyqt4 tutorials
from PyQt5 import QtCore, QtGui, QtWidgets #works for pyqt5
I'm new to it myself but in pyqt4, QtWidget was part of QtGui (QtGui.QtWidget), in pyqt5 it gets imported by itself as QtWidgets. Its only a small change in code to get the pyqt4 tutorials working in pyqt5.
I personally went back to pYqt4 to take advantage of pyqtgraph.
Look at my pyqt4 post here which walks you through using Qt Designer.
The problem was when I was running the PyQt5 configure script. The correct option to pass went like this:
> python3 configure.py --qmake [path to Qt5.x]/bin/qmake
I was providing the path up to bin, but did not specifically point to qmake. Go figure!
After running the configure script like this, I was able to import all the PyQt5 modules.
Configure pyqt with this command:
python[3] configure.py --qmake=[path to Qt5.x]/bin/qmake --verbose
Whether a qt module builds or not depends on the configure.py's check.
Take a look at the terminal output and you will find the reason why QtGui..QtWidgets was not installed correctly.
same issue, python run py ok, but in all IDE: visual studio code/PyCharm. It will show syntax error.
Finally I solved it by set env var PYTHONPATH to python site-packages path,
e.g.
PYTHONPATH=D:\Anaconda3\Lib\site-packages
I had this problem today and I solved as below:
Instead of importing like:
from PyQt5.QtGui import QIcon
Imported this way and it will just fine:
from PyQt5 import QtGui
from PyQt5.QtGui import QIcon
in PyQt5, QtGui and QtCore is located into the QtWidgets
You should import like this:
from PyQt5.QtWidgets import QtGui, QtCore
instead of
from PyQt5.QtCore import *
from PyQt5.QtGui import *
Hope this helps. :)

Resources