Import Error When trying "from PyQt5.Qt import Qt" - import

My application uses the virtual module Qt to access properties like "Qt.Checked" or "Qt.WindowModal", but in trying to get my application working on my new Windows 11 test machine, I get
Traceback (most recent call last):
File "C:\Users\<redacted-path>", line 6, in <module>
from PyQt5.Qt import Qt, QApplication, QIcon
ImportError: cannot import name 'Qt' from 'PyQt5.Qt' (C:\Users\<redacted-user>\AppData\Local\miniconda3\lib\site-packages\PyQt5\Qt.pyd)
This doesn't happen on Windows 10, Mac, Linux, or even some other Windows 11 machines. Imports work fine when addressing specific modules like from PyQt5.QtWidgets import QApplication. It's just when importing the Qt namespace module that I get an import error. I get the same error with python 3.7, 3.8, and 3.9, and when using a system install of python or a conda install. This is a fresh environment that I stood up just to test this. It wasn't resolved by using different PyQt5 version or force reinstalling it. The file in question is in the site packages directory when I inspect the PyQt5 install, so it's not a matter of a corrupted installation.
I suspect this is also contributing to the dll import errors that my users sometimes see when using the cx_freeze generated installer.
Has anyone seen this before, have resolution steps, or guidance to put me down the right path? I could just rip out the Qt import, but it is marginally quicker to import this way than to import every module on its own line.
Machine Details:
Device: Dell Latitude 3420
Processor: 11th Gen Intel(R) Core(TM) i5-1135G7 # 2.40GHz 1.38 GHz
System Type: 64-bit operating system, x64-based processor
OS Edition: Windows 11 Pro
OS Version: 22H2
OS Build:22621.1105

Related

ImportError: No module named serial in Linux

I encountered a problem with topic is ImportError: No module named serial by I use it in Linux ubuntu 20.04, and my python version is 3.8.10.
Traceback (most recent call last):
File "/home/prawee/catkin_ws/src/ros_myo_2/scripts/myo-rawNode.py", line 9, in <module>
import serial
ImportError: No module named serial
And I have pyserial version 3.5 installed. I have tried repeating the serial install which says this.
Requirement already satisfied: pyserial in /usr/local/lib/python3.8/dist-packages (3.5)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: There was an error checking the latest version of pip.
I wonder if this warning is related to problem?
This problem just happened for the first time. Before this I was able to use it normally. I have tried many ways but still don't understand how to fix it, please help me.
I am stuck in a problem import serial which I hope to be able to fix and use it again the way it used to be.

PyAudio import error : ImportError: DLL load failed: The specified module could not be found

I encountered an import problem by PyAudio.
I have a winodws 10, 64 bit, and use Anaconda and Spyder IDE with python 3.7.
I installed PyAudio in Ananconda, ran as administrator, with these commands :
cd
conda install -c conda-forge PyAudio
The installation ran without any problems.
I then restarted both Anaconda and SPYDER. PyAudio now shows up in Anaconda's list of installed packages.
When I try to import Pyaudio in Spyder (IPython console), I encounter this error message :
[1]: import pyaudio
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "", line 1, in
import pyaudio
File "C:\ProgramData\Anaconda3\lib\site-packages\pyaudio.py", line 116, in
import _portaudio as pa
ImportError: DLL load failed: The specified module could not be found.
I tried to fix it by answers to similar ImportError message issued, while other users tried to import other packages like SKlearn ... , but with no success.
Your problem (and mine) are the same. The issue is, unfortunately, the version of python you're running (in tandem with your OS).
Check out this link:
https://people.csail.mit.edu/hubert/pyaudio/#:~:text=Note%3A%20As%20of%20this%20update,4.
Under the INSTALLATION section in the link for WINDOWS, PyAudio's latest version (0.2.11) is compatible with Python versions: 2.7, 3.4, 3.5, 3.6.
My current python is 3.8.5, so you (and I) could never use PyAudio unless they added compatibilities or we revert to an above python version.
I tried to install portaudio using
conda install portaudio
but it seems like it didn't work as it should be. However,
conda install -c anaconda portaudio
solved the problem.
see the official anaconda page

DLL load failed : Python modules accessible through Spyder but import fail in cmd

I have seen many more or less related questions on this topic, but none helped me finding a way to solve my problem.
I'm not very familiar with Windows environment, deep apologies if my question sounds obvious to some extent.
Setup:
Windows 10
Python 3.7.0 (installed through latest Anaconda release)
Spyder 3.3.1
Im running a Python, that involves several modules import. I came across some module issues. For example:
from PIL import Image as PIL_Image
Works smooth in Spyder, but gives (error message in french but I guess you got the point):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\my_user_name\Anaconda3\lib\site-packages\PIL\Image.py", line 64, in <module>
from . import _imaging as core
ImportError: DLL load failed: Le module spécifié est introuvable.
If executed in Powershell or cmd.
What I tried:
Appending Anaconda's install path to my path variable before I open Powershell:
$Env:path += ";C:\Users\my_user_name\Anaconda3;C:\Users\my_user_name\Anaconda3\Scripts"
Checking that sys.path is the same in Powershell and Spyder. For both, it looks like:
['',
'C:\\Users\\my_user_name',
'C:\\Users\\my_user_name\\Anaconda3\\python37.zip',
'C:\\Users\\my_user_name\\Anaconda3\\DLLs',
'C:\\Users\\my_user_name\\Anaconda3\\lib',
'C:\\Users\\my_user_name\\Anaconda3',
'C:\\Users\\my_user_name\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\my_user_name\\.ipython']
What else could explain that my import fails outside of Spyder ?
Ok I could not find a clean way out, so let me just share my experience in case someone finds it helpful ...
The DLL failure with PIL related libs seems to be a known issue. See further explanations:
https://github.com/python-pillow/Pillow/issues/2945
PIL: DLL load failed: specified procedure could not be found
How I solved my issue:
Cleanly uninstalled anything related to Python on my laptop. Both Anaconda, isolated Python installs, Spyder ...
Re-installed the latest Anaconda. It happens to come with Python 3.7.1 instead of 3.7.0
Re-did my PIP installs of everything. Note I had to append Anaconda\Library\bin to my Windows path for PIP to work completely, which I don't recall having done with my previous installation.

Enthought Canopy 64bit on OSX: import pyglet.gl failure

Retaining question for posterity; see workaround in edit
The Pyglet package comes installed at base and isn't removable. Using the current fully updated version 1.1.4 of Pyglet, I get repeatable errors related to importing the item pyglet.gl.gl_info; for instance, upon attempting to create a pyglet.window.Window(), upon trying to import pyglet.gl, or upon attempting to import pygarrayimage via from pygarrayimage.arrayimage import ArrayInterfaceImage.
In all such cases the relevant traceback ends with the uninformative message:
/Users/[username]/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/pyglet/image/__init__.py in <module>()
142
143 from pyglet import gl
--> 144 from pyglet.gl import *
145 from pyglet.gl import gl_info
146 from pyglet import graphics
/Users/[username]/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/pyglet/gl/__init__.py in <module>()
102 from pyglet.gl.glext_arb import *
103 from pyglet.gl.glext_missing import *
--> 104 from pyglet.gl import gl_info
105
106 import sys as _sys
ImportError: cannot import name gl_info
I am using OSX 10.6.8 on an Intel processor, with Canopy 64-bit, and these are 100% repeatable.
Given the traceback one might assume gl_info mistakenly isn't included, but this isn't the case. dir(pyglet.gl.gl_info) can successfully be run.
Edit: Solved this problem.
Pyglet 1.1.4 does not support 64-bit on OSX, so until Enthought packages a newer release of Pyglet in Canopy, here is a workaround for 64-bit OSX users.
Acquire source for any release of Pyglet 1.2alpha1 or beyond.
Extract source to your directory of choice.
Append this directory to the beginning of your PYTHONPATH environment variable, in both ~/.bash_profile (for terminal shells) and /etc/launchd.conf (for GUI processes) with a line similar to: export PYTHONPATH=/Users/[username]/src/pyglet-1.2alpha1:$PYTHONPATH
Run this bash command in an unrelated directory and confirm the path printed leads to your 1.2alpha1 source directory: $ python -c "import pyglet; print pyglet.__path__[0]"
If you don't wish to modify your bash_profile, you can simply do the following:
Extract latest Pyglet source to your directory of choice and cd to that directory (it should contain a setup.py file).
Use Canopy's Python to install Pyglet by doing the following (on Mac 64 bit):
~/Library/Enthought/Canopy_64bit/User/bin/python setup.py install
The location of Canopy's Python for different platforms is listed here:
https://support.enthought.com/entries/23646538-Make-Canopy-s-Python-be-your-default-Python-i-e-on-the-PATH-

JPEG and PNG Library Use in PIL

I'm relatively new to development and I've been attempting to setup an application I'm building in Django (on Windows 7, 64 bit) to accept image uploads via ImageField. I initially installed PIL, but found that I needed JPEG and PNG libraries first. So I uninstalled PIL using "pip uninstall pil" and setup the libraries at C:\zlib-1.2.7\zlib.lib and C:\jpeg-8d\libjpeg.lib. Afterwards, I went into the setup.py in PIL and changed the following:
JPEG_ROOT = "C:/jpeg-8d"
ZLIB_ROOT = "C:/zlib-1.2.7"
I then install via:
pip install C:\Imaging-1.1.7\
I got the following at the end of the install, which suggests there's JPEG and PNG support:
Installing collected packages: PIL
Running setup.py install for PIL
WARNING: '' not a valid package name; please use only.-separated package nam
es in setup.py
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform win32 2.6.6 (r266:84297, Aug 24 2010, 18:46:32)
[MSC v.1500 32 bit (Intel)]
--------------------------------------------------------------------
*** TKINTER support not available (Tcl/Tk 8.5 libraries needed)
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.
To check the build, run the selftest.py script.
Successfully installed PIL
Cleaning up...
However, I got following when testing with selftest.py, which suggests no support:
C:\Windows\system32>python C:\Imaging-1.1.7\selftest.py
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY
--------------------------------------------------------------------
Python modules loaded from C:\Users\ayan\Desktop\Imaging-1.1.7\PIL
Binary modules loaded from C:\Python26_x86\lib\site-packages\PIL
--------------------------------------------------------------------
*** PIL CORE support not installed
*** TKINTER support not installed
*** JPEG support not installed
*** ZLIB (PNG/ZIP) support not installed
*** FREETYPE2 support not installed
*** LITTLECMS support not installed
--------------------------------------------------------------------
I also tried to work with a JPEG and got following IOError:
C:\Users\Public\Pictures\Sample Pictures>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> import os, sys
>>> import Image
>>> img = Image.open(Desert.jpg)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Desert' is not defined
>>> img = Image.open("Desert.jpg")
>>> img.save("Desert_test.jpg")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26_x86\lib\site-packages\PIL\Image.py", line 1406, in save
self.load()
File "C:\Python26_x86\lib\site-packages\PIL\ImageFile.py", line 189, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "C:\Python26_x86\lib\site-packages\PIL\Image.py", line 385, in _getdecode
r
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
This is somewhat similar to what was reported at https://stackoverflow.com/questions/10543581/pil-installation-run-issue; however, it appears that in this case, JPEGs actually aren't working. A similar problem is observed with PNGs.
It's not clear to me where in the process I've made a mistake, so any comments would be greatly appreciated. Please let me know if additional information is required, I'll endeavor to do by best to provide it.
Many thanks.
I have solved something similar but just for png support. I believe you can do the same for jpeg support as well.
First I would recommend using Pillow, a fork of PIL.
The solution I used is to manually compile on my machine (win7 64 bit) the zlib library.
And then manualy compiling the Pillow Package. I edited the Setup.py like you did to point at a directory where I put the zlib I just compiled.
I would suggest you manually compile the jpeg lib as well, and the zlib and then compile Pillow again. Make sure to uninstall previous versions of PIL/Pillow before doing it.
The link for my detailed answer of how to do it with zlib is:
https://stackoverflow.com/a/17190972/2501083
Hope this helps