Shutil cannot import WindowsError on windows - windows-7-x64

I've observed that shutil fails to import WindowsError on our windows 7 systems:
from shutil import WindowsError
File <file>, line <no>, in <module>
from shutil import WindowsError
ImportError: cannot import name WindowsError
The same statement works absolutely fine on linux. Has anyone else come across it too? Do you know how I could fix it?
Python version: 2.6.7
Linux OS: Centos 6.3
Windows OS: Windows 7 Professional x64

Got a solution from the python bug tracker:
http://bugs.python.org/issue18525
This is an implementation artifact and would not be fixed. The import statement such as above are a wrong usage. The correct usage being(if necessary):
try:
WindowsError
except NameError:
WindowsError = None

Related

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

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

ImportError: cannot import name 'StopLocust' from 'locust.exception'

I'm getting an ImportError attempting to run a Locust/Selenium script: ImportError: cannot import name 'StopLocust' from 'locust.exception'
Is there a package that I need to install?
from realbrowserlocusts import ChromeLocust
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from locust_plugins.users import WebdriverUser
from locust.exception import StopLocust
import os
from locust import TaskSet, task
The output from the Terminal window shows this:
File "c:\users\mjohns33\pycharmprojects\omni\lib\site-packages\realbrowserlocusts\core.py", line 6, in
from locust.exception import StopLocust
ImportError: cannot import name 'StopLocust' from 'locust.exception' (c:\users\mjohns33\pycharmprojects\omni\lib\site-packages\locust\exception.py)
Any ideas?
If you're using Locust 1.0+ there is no StopLocust in locust.exceptions. I'm not sure what it is you're looking to do so I don't know if it's the right thing for you to use, but there is StopUser in there that you should be able to import.
Local environment issue. Re-installing my setup.
After doing some more research I was able to resolve a couple of issues from the import error. Installing locustio solved the import issue and a follow-on issue in attempting to load the locust web page was solved by updating gevent.
So, for the full fix uninstall the current version of locust and install the locustio version. Then upgrade the gevent.
pip uninstall locust
pip install locustio==0.14.6
pip install --upgrade gevent
Realbrowserlocusts isn't compatible with the most recent versions of Locust. Downgrading to version locust 0.13.5 fixed the issue. I'm not sure exactly which of the most recent versions of locust supports realbrowserlocusts. I would like to find out though so I'm running the best of locust versions supporting running with selenium.

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

No module named 'scipy', although installed with Anaconda. Python 3 on Windows 10

I did conda install for numpy, pandas, scipy, and scikit-learn apparently all successful. I also tried to change the path in the Windows 10 registry. I only have 1 version of Python, 3.6 installed. I also installed Visual Studio. If I run the script, I get "scipy module not found". Can you explain me what's the problem, and how to fix this?
My imports look like this:
import pandas as pd
import quandl, math
import numpy as np
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
I'm following this tutorial by Sentdex:
https://www.youtube.com/watch?v=r4mwkS2T9aI&index=4&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v

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-