I'm following a tutorial of making desktop apps. with python and qt4, I downloaded and installed qt creator ide, created the .ui file and then I had to convert it using pyuic4, I've been trying a lot of things and still can't do it.
I thought that pyuic4 would be installed with Qt creator IDE, but it seems that's not the case, so I installed pyqt through macports:
sudo port install py26-pyqt4
I didn't know but that came with qt, so it was about 3 hours building it.
after installing it I tried to convert the .ui again:
$ pyuic4-2.6 principal.ui -o prin.py
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/pyuic.py", line 4, in <module>
from PyQt4 import QtCore
ImportError: No module named PyQt4
No module named PyQt4? wasn't that what I just installed?
Thanks, and excuse me if my english isn't 100% good.
I've solved it, you have to use the python of macports instead of the default that comes with OS X, to do that install python_select through macports:
sudo port install python_select
sudo python_select python26
I made some notes on building and install PyQt4 on Mac Snow Leopard.
The order is important, and there are some quirks with 64-bit libraries. The default Mac Qt libs are Carbon (32 bit), whereas Mac system Python is 64 bit and needs the Cocoa libs.
I spent a while finding the package name in Homebrew. It seems to be:
brew install pyqt
Related
Currently using Ubuntu 20.04 LTS with python3.8.5.
Its my first time using ubuntu with absolutely no previous knowledge of terminal.SO,would love to have a detailed answer if possible.
Below is terminal output when i try importing tkinter in python3.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
>>>
I have reinstalled python3 and tkinter using sudo apt.But still it shows same error.
When i run the same command in python IDLE it works without any error.
I hope this explains my problem clearly, if any other info. is required pls reply.
I also tried running the command >>>from tkinter import *
I faced the same issue on MacOS. I was using a Python virtual environment. This command worked for me:
brew install python-tk
CentOS 8 + Python 3.9.5
following are what i have doneļ¼
1st:
yum search tkinter
yum install python39-tkinter.x86_64
2nd:
yum install tk-devel
3rd: cd python3.9.5 source folder
make install
it work in my case
since I'm still using python 3.9, this code works for me:
brew install python-tk#3.9
if using brew install python-tk brew will install python-tk#3.10 which is key-only
I had the same issue. Switched from 3.8 to 3.7 and it worked. I'm using PyCharm CE, which makes it easy to switch between interpreters.
Resolved the issue it occurred because the Tkinter was installed for version 3.5 and not for the 3.8 version. For that, I installed the 3.5 version and kept only one version i.e. 3.8, and installed Tkinter again, and it worked!
This is just a workaround to make things work, but the more preferred way is to create a venv and then install the particular versions of python and libraries that are needed.
When I import tinker in python 3.7.3 on Ubuntu 18.04:
>>> import tkinter
I got:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
Then I install tk using both of the following:
sudo apt-get install python3-tk
It didn't work.
I also did all the things in Tkinter module not found on Ubuntu, still didn't work.
I noticed that when I do:
sudo apt-get install python3.7-tk
It says:
Note, selecting 'python3-tk' instead of 'python3.7-tk'
python3-tk is already the newest version (3.6.9-1~18.04).
Is tk automatically installed under python 3.6.9? How can I fix this?
I also saw a solution from https://wiki.python.org/moin/TkInter:
If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do not edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.
Could someone explain to do how to do the steps mentioned in this paragraph?
OK. I think the problem is that the newest version of tkinter for Ubuntu 18.04 is "python3-tk_3.6.9-1~18.04_i386.deb". Now I found that tk for python3.7.3 is available for other systems(e.g. python3-tk_3.7.3-1_amd64.deb). Can I download and use these ones on my system?
acw1668: Thanks this helped me a lot. I'm using Python 3.8. Using your method was able find where tkinter for Python 3.8 was install (/usr/lib/python3.8/). So i copied the files to (/usr/local/lib/python3.8/) which is where Python is installed on my computer. Now it'e working.
After installing PyQt using brew install, like so:
brew install qt
brew install sip
brew install pyqt
I try to run a sript and I get this error:
Traceback (most recent call last):
File "exampleosx.py", line 17, in <module>
from PyQt4 import QtGui
ImportError: dlopen(/Library/Python/2.7/site-packages/PyQt4/QtGui.so, 2): no suitable image found. Did find:
/Library/Python/2.7/site-packages/PyQt4/QtGui.so: mach-o, but wrong architecture
I've tried following many tutorials on how to run the code with different options but with no luck.
Adding "arch -i368" is not fixing the problem either.
I'm using OSX 10.7.5 and Python 2.7.1
Try running your script with this prefix.
VERSIONER_PYTHON_PREFER_32_BIT=no /usr/bin/python exampleosx.py
Try running your script with $arch -i386 in front on the command line, something like :
$arch -i386 python myscript.py
Because Pyqt is available for 32 bits architecture only.
I'm trying to use PySide so I did a brew install pyside pyside-tools. However, I get the following error:
>>> from PySide.QtGui import QApplication
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/PySide/QtGui.so, 2): Library not loaded: QtGui.framework/Versions/4/QtGui
Referenced from: /Library/Python/2.7/site-packages/PySide/QtGui.so
Reason: image not found
This SO question says to install python 27 and then reinstall pyside but I'm using the native python on mac osx 10.8 and it is already 2.7.2.
The Homebrew recipe for PySide seems to indicate that this should have been fixed but I'm still getting the errors. I made sure libpng is installed as well.
Looking at the path, I know that the QtGui.so file is there. Since I'm new to Python, PySide, and Qt, it is hard for me to Google and further troubleshoot.
If anyone knows why and can provide directions, I will be very grateful. It can involve uninstalling a bunch of stuff and reinstalling. Please give detailed instructions. I did uninstall and try to reinstall and got the same result.
Thank you.
I was getting the same error, and I'm using Python installed via Homebrew. I found two PySide libraries in /Library/Python/2.7/site-packages/ . Moving them out of the way, and re-building/installing PySide through Homebrew worked.
I tried the import you gave - I am using same system environment. It worked fine. try: brew update and re-install.
Got the same error when running ipython qtconsole which will import PySide to provide a Qt console.
Finally I thought there might be something wrong after PySide's installation. So I run pyside_postinstall.py -install manually which should be automatically run after PySide is installed, and this fixed my problem. Hopes working for your too!
I'm using Ubuntu 11.10, which came pre-installed with Python 2.7.3.
I installed the python3 package, and the python3-tk package, via apt-get install, and they worked together "out of the box".
But though I've installed the python-tk package, I can't figure out how to get Python2.7 to see it. I get the error message below when I try to import it.
import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
edit: I also ran the following based on Python-tk package not recognized in Python 2.7.3, and got:
$ file /usr/lib/libtk8.5.so.0
/usr/lib/libtk8.5.so.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, stripped
$ uname -a
Linux bugbot 3.0.0-23-generic-pae #39-Ubuntu SMP Thu Jul 19 19:39:19 UTC 2012 i686 i686 i386 GNU/Linux
I figured it out after way too much time spent on this problem, so hopefully I can save someone else the hassle.
I found this old bug report deemed invalid that mentioned the exact problem I was having, I had Tkinter.py, but it couldn't find the module _tkinter: http://bugs.python.org/issue8555
I installed the tk-dev package with apt-get, and rebuilt Python using ./configure, make, and make install in the Python2.7.3 directory. And now my Python2.7 can import Tkinter, yay!
I'm a little miffed that the tk-dev package isn't mentioned at all in the Python installation documentation.... below is another helpful resource on missing modules in Python if, like me, someone should discover they are missing more than _tkinter.
Building Python and more on missing modules
I had same issue with python3.4 (ImportError: No module named '_tkinter')
sudo apt-get install tk-dev
got to python source directory
./configure
make
sudo make install
The following solved the issue for me on Linux Mint 16:
sudo apt-get install tk-dev python-tk
I use virtualenv but did not want to compile python, in order to make the python support tk, python-tk should be installed.