Unable to parse valid xml in cpython 3.8 - python-3.x

I'm trying to parse xml file in Python script, which is working inside the C++ application. When I'm trying to run this script:
import xml.etree.ElementTree as ET
root = ET.parse('somexml.xml' ).getroot()
I always receive an error:
RunScriptFail: Traceback (most recent call last):
File "xml\etree\ElementTree.py", line 1500, in __init__
File "<frozen zipimport>", line 259, in load_module
File "xml\parsers\expat.py", line 4, in <module>
ModuleNotFoundError: No module named 'pyexpat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "xml\etree\ElementTree.py", line 1503, in __init__
ModuleNotFoundError: No module named 'pyexpat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "xml\etree\ElementTree.py", line 1202, in parse
File "xml\etree\ElementTree.py", line 589, in parse
File "xml\etree\ElementTree.py", line 1505, in __init__
ImportError: No module named expat; use SimpleXMLTreeBuilder instead
Error parsing script
But pyexpat.pyd exists in lib folder of cpython. How can I fix it? Or may be I can use some workaround for it?
Solution from Using SimpleXMLTreeBuilder in elementtree works for me

I found that needed pyexpat.pyd is not copied into distribution. I added it ad that resolved my issue

Related

ImportError: DLL load failed while importing QtGui: The specified module could not be found

I get this error when I try to run labelimg on windows
Traceback (most recent call last):
File "C:\Users\okeon\AppData\Roaming\Python\Python39\site-packages\labelImg\labelImg.py", line 18, in
from PyQt5.QtGui import *
ImportError: DLL load failed while importing QtGui: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\okeon\anaconda3\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\okeon\anaconda3\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\okeon\AppData\Roaming\Python\Python39\Scripts\labelImg.exe_main.py", line 4, in
File "C:\Users\okeon\AppData\Roaming\Python\Python39\site-packages\labelImg\labelImg.py", line 29, in
from PyQt4.QtGui import *
ModuleNotFoundError: No module named 'PyQt4'
Tried installing modules and imports based on errors, but nothing is working. Anyone with experience on this?
A walk around I discovered was to install labelimg and pyqt5 as packages in anaconda and launch labelimg from there. It worked for me

Passing .la or .a file as a library in cygwin in an attempt to run a python wrapper

I'm trying to make an Iperf3 python wrapper work in cygwin. The wrapper requires Iperf3 to be installed and needs a library called "libiperf.so.0" to work. In Ubuntu, the wrapper automatically finds this Iperf3 library. In cygwin, I compiled, built, and installed Iperf3 from source and it is working, so I'm assuming the library asked by the wrapper can be found.
However I could only find libiperf.a and libiperf.la on cygwin, not libiperf.so.0, and, from what I researched, those are the libraries used by Iperf when you compile, build and install it in cygwin.
So I tried passing libiperf.a and libiperf.la as libraries to the python wrapper. But I get either "OSError: Permission Dienied" (when passing libiperf.a) or "OSError: Exec format error" (when passing libiperf.la), followed by another "OSError: Couldn't find shared library <path_to_library>, is iperf3 installed?"
Here's the complete error output when i pass libiperf.la as library:
>>> client = iperf3.Client(lib_name="/cygdrive/c/cygwin64/usr/local/lib/libiperf.la")
Exception ignored in: <function IPerf3.__del__ at 0x6fffffd1b700>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/iperf3/iperf3.py", line 213, in __del__
os.close(self._stdout_fd)
AttributeError: 'Client' object has no attribute '_stdout_fd'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/iperf3/iperf3.py", line 106, in __init__
self.lib = cdll.LoadLibrary(lib_name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: Exec format error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/iperf3/iperf3.py", line 418, in __init__
super(Client, self).__init__(role='c', *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/iperf3/iperf3.py", line 108, in __init__
raise OSError(
OSError: Couldn't find shared library /cygdrive/c/cygwin64/usr/local/lib/libiperf.la, is iperf3 installed?
Here's the complete error output when i pass libiperf.a as library:
>>> client = iperf3.Client(lib_name="/cygdrive/c/cygwin64/usr/local/lib/libiperf.a")
Exception ignored in: <function IPerf3.__del__ at 0x6fffffd1b700>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/iperf3/iperf3.py", line 213, in __del__
os.close(self._stdout_fd)
AttributeError: 'Client' object has no attribute '_stdout_fd'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/iperf3/iperf3.py", line 106, in __init__
self.lib = cdll.LoadLibrary(lib_name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/iperf3/iperf3.py", line 418, in __init__
super(Client, self).__init__(role='c', *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/iperf3/iperf3.py", line 108, in __init__
raise OSError(
OSError: Couldn't find shared library /cygdrive/c/cygwin64/usr/local/lib/libiperf.a, is iperf3 installed?
According to this question the Exec format error means the file format is not supported by the OS, but Iperf3 is working correctly on cygwin. So for some reason the libiperf.la or libiperf.a are working for Iperf3 but arent accepted by the wrapper.
Also could I trust the "OSError: Exec format error"? Because down in the error output it says the library couldn't be found. If the library couldn't even be found how can it say there was a format error?
I also tried
ln ./libiperf.a ./libiperf.so.0
and
ln ./libiperf.la ./libiperf.so.0
trying to trick the wrapper into accepting the libraries but I keep getting the same errors as before.
I feel like this wrapper cant be run in cygwin because of the different libraries iperf3 uses when its installed in the cygwin environment, but maybe not. Am I missing something to make this work?

AWS Glue: Installing pandas==1.0.3 on AWS Glue python shell jobs Python library path

I have requirement where I need to use pandas dataframe attribute of Explode and json_normalize. It seems by default python glue shell runs 0.24.2 pandas version.
I was able to use .whl version pandas-0.23.0-cp36-cp36m-manylinux1_x86_64.whl.When I tried providing .whl files for pandas version by pandas-0.25.3-cp35-cp35m-manylinux1_x86_64.whl,pandas-1.0.0-cp38-cp38-manylinux1_x86_64.whl,pandas-1.0.3-cp38-cp38-manylinux1_x86_64.whl which all are failing to load with Below error message:
Traceback (most recent call last):
File "/glue/lib/installation/pandas/__init__.py", line 32, in <module>
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
File "/glue/lib/installation/pandas/_libs/__init__.py", line 3, in <module>
from .tslibs import (
File "/glue/lib/installation/pandas/_libs/tslibs/__init__.py", line 3, in <module>
from .conversion import localize_pydatetime, normalize_date
ModuleNotFoundError: No module named 'pandas._libs.tslibs.conversion'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/runscript.py", line 211, in <module>
runpy.run_path(temp_file_path, run_name='__main__')
File "/usr/local/lib/python3.6/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/usr/local/lib/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/glue-python-scripts-maew3inn/EPP_Json_To_CSV.py", line 1, in <module>
File "/glue/lib/installation/pandas/__init__.py", line 37, in <module>
f"C extension: {module} not built. If you want to import "
ImportError: C extension: No module named 'pandas._libs.tslibs.conversion' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/runscript.py", line 230, in <module>
raise e_type(e_value).with_traceback(new_stack)
File "/tmp/glue-python-scripts-maew3inn/EPP_Json_To_CSV.py", line 1, in <module>
File "/glue/lib/installation/pandas/__init__.py", line 37, in <module>
f"C extension: {module} not built. If you want to import "
ImportError: C extension: No module named 'pandas._libs.tslibs.conversion' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
Currently, you cannot import pandas library to Glue. AWS GLUE DOCUMENTATION
Only pure Python libraries can be used. Libraries that rely on C
extensions, such as the pandas Python Data Analysis Library, are not
yet supported.
It's a duplicate question: Use AWS Glue Python with NumPy and Pandas Python Packages

autosklearn installation. Error: No module named 'sklearn.metrics.classification'

I'm trying to execute a script that uses Scikit and autosklearn on Ubuntu 20, python 3.8
I have followed the instructions to install sckit https://scikit-learn.org/stable/install.html and autosklearn installation https://automl.github.io/auto-sklearn/master/installation.html
However I'm getting
Exception ignored in: <function AutoML.__del__ at 0x7f37c6ee9160>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/autosklearn/automl.py", line 1380, in __del__
self._backend.context.delete_directories(force=False)
AttributeError: 'AutoMLClassifier' object has no attribute '_backend'
Traceback (most recent call last):
File "myscript.py", line 261, in <module>
import model_snow_magn_only_package
File "/myfolder/myscript.py", line 150, in <module>
clf = pickle.load(open(model_name, "rb"))
ModuleNotFoundError: No module named 'sklearn.metrics.classification'
I have tried other releases of these packages but without success.
Does anyone have an idea of which releases/packages to install to make it work?

having issue importing tensorflow module in windows

import tensorflow
Traceback (most recent call last):
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(file)])
File "D:\python36\lib\imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "D:\python36\lib\site-packages\tensorflow__init__.py", line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "D:\python36\lib\site-packages\tensorflow\python__init__.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(file)])
File "D:\python36\lib\imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
1. Use Anaconda
Anaconda uses conda distribution index which is similar to PyPI. The TensorFlow conda build uses MKL ( Intel Math Kernel Library ). It works without AVX.
Download Anaconda as mentioned here and create a new conda enviroment as mentioned here.
Run this command:
conda install tensorflow
2. Use builds from tensorflow-windows-wheel repo.
This repo contains a number of TensorFlow pip wheel files which are build using SSE instead of AVX. SSE build run without any compilation errors. Use this file from the repo.
Hope this helps.

Resources