pyuic4 ImportError: No module named port_v2.ascii_upper - python

I'm trying to convert a Qt widget created with Qt Designer in a py file using ' pyuic4
I just do
pyuic4 widget.ui -o ui_widget.py
But I get this error:
Traceback (most recent call last):
File "/usr/bin/pyuic4", line 3, in <module>
import PyQt4.uic.pyuic
File "/usr/lib/python3/dist-packages/PyQt4/uic/__init__.py", line 43, in <module>
from PyQt4.uic.Compiler import indenter, compiler
File "/usr/lib/python3/dist-packages/PyQt4/uic/Compiler/compiler.py", line 43, in <module>
from PyQt4.uic.properties import Properties
File "/usr/lib/python3/dist-packages/PyQt4/uic/properties.py", line 51, in <module>
from PyQt4.uic.port_v2.ascii_upper import ascii_upper
ImportError: No module named port_v2.ascii_upper
I have been researching the involved modules and I can see this lines in properties.py and pyuic.py
if sys.hexversion >= 0x03000000:
from PyQt4.uic.port_v3.ascii_upper import ascii_upper
else:
from PyQt4.uic.port_v2.ascii_upper import ascii_upper
(I can see in Riverbank's page that there are a branch with v2 ascii, but I haven't installed)
If I do in command line:
python (v2.7.12)
>>> import sys
>>> print hex(sys.hexversion)
0x2070cf0
>>>
Then I do the same in python3 (3.5.2)
>>> import sys
>>> print (hex(sys.hexversion))
0x30502f0
>>>
Well...looks as if pyuic4 calls a python 2 version. But I don't know what I need for execute pyuic4 with python3
Another data related with PyQt4 (I don't know if it's useful):
>>> import PyQt4
>>> from PyQt4 import QtCore
>>> print ((QtCore.PYQT_VERSION_STR, QtCore.QT_VERSION_STR))
('4.11.4', '4.8.7')
>>>
Edit:
This is installed from pyqt4-dev-tools package (linux mint).
If I try to install using PIP I get this error:
pip3 install pyuic4
Collecting pyuic4
Could not find a version that
satisfies the requirement pyuic4 (from versions: ) No matching
distribution found for pyuic4 You are using pip version 8.1.1, however
version 19.0.3 is available. You should consider upgrading via the
'pip install --upgrade pip' command.
Edit2 and posible solution
Thanks to #ekhumoro I've got solved my problem. This is the content of /usr/bin/pyuic4
#! /usr/bin/python
# there's no main function, so just import the module
import PyQt4.uic.pyuic
I need to point to python3, so I've just modify the first line:
#! /usr/bin/python3
Thanks a lot!

Related

Install labelme annotation tools

I tried to install labelme annotation tools on Mac os 10.11.x from this link labelme using the virtual environment method listed below:
# python3
conda create --name=labelme python=3.6
source activate labelme
# conda install pyqt
pip3 install pyqt5 # pyqt5 can be installed via pip on python3
pip3 install labelme
When I run labelme on terminal I get this error:
File "/Users/xxx/anaconda3/lib/python3.6/site-packages/labelme/app.py", line 32, in <module>
from PyQt5.QtGui import *
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/PyQt5/QtGui.so, 2):
Symbol not found: _PyInt_AsLong
Referenced from: /usr/local/lib/python2.7/site-packages/PyQt5/QtGui.so
Expected in: flat namespace in /usr/local/lib/python2.7/site-packages/PyQt5/QtGui.so
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/xxxx/anaconda3/bin/labelme", line 7, in <module>
from labelme.app import main
File "/Users/rafikgouiaa/anaconda3/lib/python3.6/site-packages/labelme/app.py", line 37, in <module>
from PyQt4.QtGui import *
ModuleNotFoundError: No module named 'PyQt4'**
It seems that labelme looks for pyqt5 in Python 2.7, not in Python 3.6 where pyqt5 is installed.
Any help for installing labelme or any other tools other than labelme and Matlab tools?

How to install python packages to embedded python in GDB/ clion2017.1

I'm using CLion 2017.1 and GDB for debugging. GDB compiled with python 2.7 support, but with no modules.
I wish to use matplotlib in order to plot some debug data (using GDB image watch) but there is no matplotlib presence. and no pip to install it.
I've tried to install pip using (gdb) python import get_pip but
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/user/temp/get_pip.py", line 28, in <module>
import tempfile
File "/home/user/clion-2016.3.4/bin/gdb/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
File "/home/user/clion-2016.3.4/bin/gdb/lib/python2.7/random.py", line 48, in <module>
from binascii import hexlify as _hexlify
ImportError: No module named binascii
Error while executing Python code.
So I don't know how to bootstrap instullation of additional modules into GDB's embedded python.
Any idea how to do that?
I've tried to install pip using (gdb) python import get_pip but
You need not install python modules from gdb shell. You can install them from command line as usual with your package manager or with pip. Make sure that you installed Python2 version of module. Once the module is installed you can use it in gdb embedded python:
$ gdb -q
(gdb) python
>import matplotlib
>end
(gdb)

pyqt is installed but it won't import (Mac)

I installed PyQt4 and I have xcode, Qt, Sip, and Python 2.7. When I check in terminal, it says that PyQt is installed and when I view the path there is no PyQt in the path. I have put it in the path before but it goes away when I close the shell. When I try and import it it says no module named PyQt4. Help
brew install pyqt
Warning: pyqt-4.11.4 already installed
>>> for f in sys.path:
print f
/Users/lucygrant/Documents
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
/Library/Python/2.7/site-packages
>>> import PyQt4
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import PyQt4
ImportError: No module named PyQt4
Assuming that adding PyQt4 to PATH solved your problem before, do it again except now do it in the ~/.bashrc file. So, as follows:
Add PyQt4 to PATH in ~/.bashrc as you have previously done.
source ~/.bashrc from command line.
Reattempt import

Python 2.7: Import Error for 'matplotlib' and 'plotly' (OS X)

I am trying to import matplotlib and plotly in my python script to plot a simple distribution. Earlier when I was running the script, it was displaying nothing on the command-line and it seemed that it was simply processing the import statement.
To debug it, I upgraded python using brew install python after that and did a pip install --upgrade pip after that. Using the upgraded pip, I made sure that matplotlib and plotly are installed. But, upon running the script, I am getting the following error on command-line:
$ python script.py
Traceback (most recent call last):
File "script.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 110, in <module>
import io
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Can someone please help me resolve this issue?
Thanks in advance.
I found a similar SO issue for Selenium. The problem appeared to be a python issue after updating and the solution there was to type hash -r python in the terminal. Worth a try.

How to get past `import gv` in python-graph?

I would like to run the python/graphviz example code.
First I install python-graph
sudo easy_install python-graph-core
sudo easy_install python-graph-dot
then I install graphviz
sudo port install graphviz
Since the writer of the example code seems to be on linux and I'm on OS X, I replace
import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz/python/')
sys.path.append('/usr/lib64/graphviz/python/')
import gv
with
import sys
sys.path.append('..')
sys.path.append('/Library/Python/2.7/site-packages')
sys.path.append('/opt/local/lib/graphviz')
import gv
I insert the former because easy_install has reported that both python-graph modules have been installed in
/Library/Python/2.7/site-packages/python_graph_core-1.8.2-py2.7.egg
/Library/Python/2.7/site-packages/pyparsing-2.0.3-py2.7.egg
I insert the latter because that's where I see MacPorts has installed graphviz.
Still, trying to run the example code stops with:
Traceback (most recent call last):
File "./graph-example.py", line 12, in <module>
import gv
ImportError: No module named gv
How do I get past import gv?
Try running:
sudo pip install pygraphviz
Then you should just be able to use:
import gv
in python.

Categories