PyQt4 Missing in import statement - python

I tried to download PyQt4 however it no lomger appears to be available, so I downloaded the nearest thing to it that I could find PyQt-win-gpl-4.8.4. The problem is when I try to follow the examples in "Rapid GUI programming with Python and QT" i cannot use some of the imports e.g. from PyQt4.QtCore import * gives me the following Error (copied from IDLE):
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
`import sys
`import time
`from PyQt4.QtCore import *
**Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from PyQt4.QtCore import *
ImportError: DLL load failed: The specified procedure could not be found.
>>>**

You downloaded a source package, so you'd have to compile everything. Try the binary package at the bottom of Riverbank's page. As you have python 2.7 on a 32bit system, you want to download PyQt-Py2.7-x86-gpl-4.8.4-1.exe.

As far as I know you could just intall pyqt4 with either:
pip install pyqt4
or
easy_insatll pyqt4
or
http://www.riverbankcomputing.co.uk/software/pyqt/download
-> under Binary Packages choose the one that correspondends to your python version and system
for you this schould be the right one: pyqt4 py2.7 32bit

Related

How to install tkinter for python3.10.6 on CentOS7?

First, I installed openssl 1.1.1q package using the following source on CentOS7.
(https://www.openssl.org/source/openssl-1.1.1q.tar.gz)
Second, I installed tcl/tk packages using the following sources.
(https://prdownloads.sourceforge.net/tcl/tcl8.6.12-src.tar.gz
https://prdownloads.sourceforge.net/tcl/tk8.6.12-src.tar.gz)
Finally, I installed python 3.10.6 using the following source.
(https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz)
However, I can't use tkinter module.
For example, when I import tkinter I get the bellow message.
Python 3.10.6 (main, Aug 18 2022, 11:15:38) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
The yum doesn't support the python 3.10.x version. How can I resolve this problem without yum?
What should I do to use tkinter?
You are importing tkinter in a wrong way, it is like this
import tkinter
tkinter is a preinstalled library in python, to test it open cmd and type
python -m tkinter
a small window should appear, if it does then it is working

python import works interactively but not from script

Disclaimer: I'm not a Windows expert, so this may be something idiosyncratic to Windows.
I'm observing a situation where I can import a module in interactive mode but not when requested from a file. Here is foo.py in its entirety:
#!/usr/bin/env python
import pyftdi
When I try to run this in Python 3.6.4, it fails:
E:\>py foo.py
Traceback (most recent call last):
File "foo.py", line 2, in <module>
import pyftdi
ImportError: No module named pyftdi
...but when I import the module interactively, it succeeds:
E:\>py
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyftdi
>>>
(FWIW, I don't get an error when repeating this under Mac OS X.)
Any thoughts about what's going on?
The problem is most likely that the version of python is different and has different modules installed. To fix this you can simply do py -3.6 foo.py instead of py foo.py.
Working directory
I had a situation where the script was importing from it's working directory and the shell was importing from the global libraries.

How do I diagnose ImportError: DLL load failed when loading native Windows python modules in a virtualenv?

I am using Python 3.x and a virtualenv -- not conda, just a plain virtualenv.
I activate the venv and run pip install opencv-python. However,
import cv2 gives me a DLL not found error:
(tf) C:\>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\src\venv\tf\lib\site-packages\cv2\__init__.py", line 4, in <module>
from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
>>>
Is this a virtualenv bug? How do I figure out which module/dll is missing?
On resolving "module could not be found" errors in general
Try using either Microsoft's Dependency Walker or lucasg's Dependencies on the module being loaded. Be sure to run Dependencies.exe from your virtualenv's command prompt, so it picks up your modified PATH.
The import line is from .cv2 import *, so the module being loaded is in the same directory as __init__.py (this is the leading .) and named cv2-SOMETHING.pyd (this is what native Python modules look like). Load that file into Dependencies.exe and it will show you the DLL that Windows wants but can't find.
In this case, the DLL is Python3.dll. Why is it missing? Because of a virtualenv bug that is fixed, but hasn't made its way into a release -- there hasn't been a release in more than a year.
On resolving this issue in particular
The github issue suggests a fix: use venv.
Alternatively you can copy the missing python3.dll into your virtualenv by hand. You'll have to do this for every virtualenv you create.
copy "c:\Program Files\Python36\python3.dll" "c:\src\venv\tf\Scripts\"

Why is this module not being found when I run the script but is in the interpreter?

I'm trying to import the tkinter module into my script. I have it installed since the interpreter is able to import it with no problems:
C:\Users\Nacht\Dropbox\Scripts>python
Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
Imports fine, no problem. But now when I try to run a script that has the line import tkinter....
C:\Users\Nacht\Dropbox\Scripts>t ls
Traceback (most recent call last):
File "C:\Users\Nacht\Dropbox\Scripts\t.py", line 5, in <module>
import tkinter
ImportError: No module named tkinter
where t is the name of the script and ls a command (it is a command-line interface).
How can the interpreter see it but not the script? Thanks.
EDIT:
The sys.path says, for the interpreter:
C:\Python32\lib\site-packages\distribute-0.6.24-py3.2.egg
C:\Python32\lib\site-packages\selenium-2.15.0-py3.2.egg
C:\Windows\system32\python32.zip
C:\Python32\DLLs
C:\Python32\lib
C:\Python32
C:\Python32\lib\site-packages
C:\Python32\lib\site-packages\win32
C:\Python32\lib\site-packages\win32\lib
C:\Python32\lib\site-packages\Pythonwin
and for the script:
C:\Users\Nacht\Dropbox\Scripts
C:\Python27\lib\site-packages\distribute-0.6.24-py2.7.egg
C:\Windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info
The script appears to be running with Python 2.7 but when you run the interpreter directly, it is using Python 3.2. As mentioned by #DSM, the name of Tkinter was different (perhaps there are other differences?).
May be there is a problem with path. It can't find the tkinter module. Setting up correct path try to import again.

PyQt4 can't import Qsci

I'm installing PyQt4 on an old Linux system (CentOS 4.4) that can't be upgraded for hardware compatibility reasons. I've got Python 2.6, QT4 and SIP installed, and the installation of PyQt4 didn't give me any errors.
When I run Python, this happens:
Python 2.6.2 (r262:71600, May 11 2011, 14:18:37)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
>>> import PyQt4.Qsci
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Qsci
I looked around, and found /usr/local/lib/python2.6/site-packages/PyQt4/uic/widget-plugins/qscintilla.py, which is almost empty of non-comment stuff:
pluginType = MODULE
def moduleInformation():
return "PyQt4.Qsci", ("QsciScintilla", )
Any ideas?
You need to install qscintilla separately. If PyQt is already installed, then you should just have to install the qscintilla python bindings. Hopefully this fixes your issue!

Categories

Resources