AttributeError: module 'collections' has no attribute - python

ide Pycharm. Google SDK installed lastest. What the problem? i used Python Interpreter 3.10 lastest. frozendict installed lastest, uplink installed, mapping installed
File "C:\Users\vgorbunov\AppData\Roaming\Python\Python310\site-packages\allure\pytest_plugin.py", line 9, in <module>
from allure.common import AllureImpl, StepContext
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "C:\Users\vgorbunov\AppData\Local\Programs\Python\Python310\lib\site-packages\_pytest\assertion\rewrite.py", line 168, in exec_module
exec(co, module.__dict__)
File "C:\Users\vgorbunov\AppData\Roaming\Python\Python310\site-packages\allure\common.py", line 19, in <module>
from allure.structure import Attach, TestStep, TestCase, TestSuite, Failure, Environment, EnvParameter
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "C:\Users\vgorbunov\AppData\Local\Programs\Python\Python310\lib\site-packages\_pytest\assertion\rewrite.py", line 168, in exec_module
exec(co, module.__dict__)
File "C:\Users\vgorbunov\AppData\Roaming\Python\Python310\site-packages\allure\structure.py", line 14, in <module>
class Attach(xmlfied('attachment',
File "C:\Users\vgorbunov\AppData\Roaming\Python\Python310\site-packages\allure\rules.py", line 116, in xmlfied
class MyImpl(namedlist('XMLFied', [(item[0], None) for item in items])):
File "C:\Users\vgorbunov\AppData\Roaming\Python\Python310\site-packages\namedlist.py", line 398, in namedlist
fields, defaults = _fields_and_defaults(typename, field_names, default, rename)
File "C:\Users\vgorbunov\AppData\Roaming\Python\Python310\site-packages\namedlist.py", line 252, in _fields_and_defaults
if isinstance(field_names, _collections.Collection):
AttributeError: module 'collections' has no attribute 'Mapping'

Related

Getting File "<frozen importlib._bootstrap>", line 991, in _find_and_load on spark-submit

I am currently on Python: 3.7.9, spark: spark-2.4.6-bin-hadoop2.6
In this project venv, I have the settings as:
kafka-python 2.0.2
pip 21.2.4
py4j 0.10.9
pyspark 2.4.6
setuptools 57.4.0
System environment variables:
SPARK_HOME C:\spark-2.4.6-bin-hadoop2.6\spark-2.4.6-bin-hadoop2.6
PYTHONPATH %SPARK_HOME%\python;%SPARK_HOME%\python\lib\py4j-0.10.9-src.zip;%PYTHONPATH%
PATH %SPARK_HOME%\bin;%SPARK_HOME%\python;%PATH%
JAVA_HOME C:\Program Files\Java\jdk1.8.0_261
I am trying to spark-submit following code in Python:
import sys
from pyspark import SparkContext, SparkConf
from pyspark.streaming import StreamingContext
from pyspark.streaming.kafka import KafkaUtils
from kafka import KafkaConsumer
kafka_consumer.py is located in C:\Users\MANU\PycharmProjects\pythonProject1
Command I ran: (venv) C:\Users\MANU\PycharmProjects\pythonProject1>spark-submit kafka_consumer.py
I get this in Console:
Traceback (most recent call last):
File "C:/Users/MANU/PycharmProjects/pythonProject1/kafka_consumer.py", line 1, in <module>
from pyspark import SparkContext, SparkConf
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\spark-2.4.6-bin-hadoop2.6\spark-2.4.6-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\__init__.py", line 51, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\spark-2.4.6-bin-hadoop2.6\spark-2.4.6-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\context.py", line 31, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\spark-2.4.6-bin-hadoop2.6\spark-2.4.6-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\accumulators.py", line 97, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\spark-2.4.6-bin-hadoop2.6\spark-2.4.6-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\serializers.py", line 72, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\spark-2.4.6-bin-hadoop2.6\spark-2.4.6-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\cloudpickle.py", line 145, in <module>
File "C:\spark-2.4.6-bin-hadoop2.6\spark-2.4.6-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\cloudpickle.py", line 126, in _make_cell_set_template_code
TypeError: an integer is required (got type bytes)
log4j:WARN No appenders could be found for logger (org.apache.spark.util.ShutdownHookManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

How to fix "OSError: cannot open profile file" using Pyinstaller

I am working on a small script, which is going to open external .PSD and do some logging from it.
I am using psd_tools to work with PSD. It uses PIL.
Everything works fine until I bundle it into .EXE with pyinstaller.
Then it throws OSError: cannot open profile file.
I cant figure out whether the problem is in PIL, psd_tools or pyinstaller(Well, I am pretty newbie though).
Here is the code:
from psd_tools import *
psd = PSDImage.load('C:\python3\layers.psd')
print('success')
Here is the traceback:
Traceback (most recent call last):
File "layers_tr.py", line 1, in <module>
from psd_tools import *
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\Alexander\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\psd_tools\__init__.py", line 2, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\Alexander\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\psd_tools\user_api\psd_image.py", line 10, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\Alexander\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\psd_tools\user_api\pil_support.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\Alexander\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\psd_tools\icc_profiles\__init__.py", line 10, in <module>
File "site-packages\PIL\ImageCms.py", line 162, in __init__
OSError: cannot open profile file
[12424] Failed to execute script layers_tr
Any help pls
Updaing psd_tools with
pip install -U psd_tools
solved the problem. Big Thanks to M. R.

Error when importing keyring library in python

I keep getting the same error when I import the keyring library. Just adding 'import keyring' to the code causes this error to appear. I have tried installing the library again, but that didn't solve it.
I'm using python 3.5 in pythonanywhere.
Can somebody help me figure out what might be going on or what I else I can try to do to fix it?
This is the Error message.
Traceback (most recent call last):
File "/home/Marketscale/Tests/OAuth Test.py", line 3, in <module> import keyring
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "/home/Marketscale/.local/lib/python3.5/site-packages/keyring-10.3.2-py3.5.egg/keyring/__init__.py", line 6, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "/home/Marketscale/.local/lib/python3.5/site-packages/keyring-10.3.2-py3.5.egg/keyring/core.py", line 149, in <module>
File "/home/Marketscale/.local/lib/python3.5/site-packages/keyring-10.3.2-py3.5.egg/keyring/core.py", line 65, in init_backend
File "/home/Marketscale/.local/lib/python3.5/site-packages/keyring-10.3.2-py3.5.egg/keyring/util/__init__.py", line 20, in wrapper
File "/home/Marketscale/.local/lib/python3.5/site-packages/keyring-10.3.2-py3.5.egg/keyring/backend.py", line 179, in get_all_keyring
File "/home/Marketscale/.local/lib/python3.5/site-packages/keyring-10.3.2-py3.5.egg/keyring/backend.py", line 139, in _load_backends
File "/home/Marketscale/.local/lib/python3.5/site-packages/keyring-10.3.2-py3.5.egg/keyring/backend.py", line 131, in _load_backend
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "/home/Marketscale/.local/lib/python3.5/site-packages/keyring-10.3.2-py3.5.egg/keyring/backends/SecretService.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "/home/Marketscale/.local/lib/python3.5/site-packages/SecretStorage-2.3.1-py3.5.egg/secretstorage/__init__.py", line 13, in <module>
File "/usr/lib/python3/dist-packages/dbus/__init__.py", line 81, in <module> import dbus.exceptions as exceptions
AttributeError: module 'dbus' has no attribute 'exceptions'
>>>
Thank you in advance for any help you can provide.
My guess is that there's some kind of conflict between one of the system-installed modules and the ones you've installed with pip install --user into ~/.local
I suggest switching to a virtualenv to get a "clean" set of modules/dependencies. More info here: https://help.pythonanywhere.com/pages/Virtualenvs

Error when packaging selenium with py2exe

I am using a python 3.4 environment in Anaconda 4.3, and I'm attempting to use py2exe to package a python script that uses selenium. The script runs perfectly as a .py file, but the .exe is returning an error when attempting to import the webdriver from the selenium module with the import statement:
from selenium import webdriver
This is the traceback returned in the console:
Traceback (most recent call last):
File "my_script.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Users\me\.conda\envs\py34\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Users\me\.conda\envs\py34\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 40, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Users\me\.conda\envs\py34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 25, in <module>
from .webelement import WebElement
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Users\me\.conda\envs\py34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 40, in <module>
getAttribute_js = pkgutil.get_data(__package__, 'getAttribute.js').decode('utf8')
File "C:\Users\me\.conda\envs\py34\lib\pkgutil.py", line 611, in get_data
spec = importlib.util.find_spec(package)
File "C:\Users\me\.conda\envs\py34\lib\importlib\util.py", line 81, in find_spec
fullname = resolve_name(name, package) if name.startswith('.') else name
AttributeError: 'NoneType' object has no attribute 'startswith'
Edited to phrase this as an actual question: This import statement works fine when running the file as a .py script. Why would this only happen after being packaged by py2exe, and is there some kind of option I am missing in the py2exe setup file?

Xlwings module causes PyInstaller EXE to throw exception

I'm trying to freeze a simple Python 3.4 script called test.py using pyinstaller. The script imports version 0.7.0 of the xlwings module (which I installed via pip), and then print a message.
import xlwings
print("Fine!")
If I remove the xlwings import, then pyinstaller test.py generates an EXE (I'm on Windows 10) inside the dist folder that prints the "Fine" message and then exits. But, if I import the xlwings module, the command generates an EXE that prints this message and then quits (not printing the "Fine" message):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\xlwings\__init__.py", line 20, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\xlwings\_xlwindows.py", line 29, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\pandas\__init__.py", line 7, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 573, in load_module
module = loader.load_module(fullname)
File "pandas\tslib.pyx", line 55, in init pandas.tslib (pandas\tslib.c:102924)
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "dateutil\zoneinfo\__init__.py", line 31, in <module>
File "dateutil\zoneinfo\__init__.py", line 24, in getzoneinfofile
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\OrangeFlash81\\AppData\\Local\\Temp\\_MEI102122\\dateutil\\zoneinfo'
test returned -1
I'm aware that cx_Freeze has issues when dateutil is imported, and this error message references dateutil. Does pyinstaller suffer the same issues, and if so, how can I resolve them?
It's not exactly a solution, but I decided to switch to using the XLRD module, which does everything I need and works flawlessly with pyinstaller; changing xlwings code to use XLRD isn't too difficult either.

Categories