I'm learning Xpath and XSLT using Python 2.6.6-64bit on my unix workstation. For Xpath, I'm using the xpath module provided in PyXml-0.8.4.
However, the import line itself throws the following error:
Traceback (most recent call last):
File "xp.py", line 7, in <module>
from xml.xpath import Evaluate
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/__init__.py", line 112, in <module>
from pyxpath import ExprParserFactory
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/pyxpath.py", line 59, in <module>
from xml.xpath.ParsedAbbreviatedRelativeLocationPath import ParsedAbbreviatedRelativeLocationPath
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/ParsedAbbreviatedRelativeLocationPath.py", line 31
as = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self')
^
SyntaxError: invalid syntax
Looking it up led me to understand that this is because 'as' is a reserved name in python-2.6 and PyXML-0.8.4 tries to redefine it. However, there are no directions on how to resolve this issue.
Please advise.
PyXML is obsolete and should not be used (see here). That's why there are no updates for it. Many features that were included in it were added to Python's standard library. There are also fully-supported third-party packages for Python XML processing like lxml.
Related
I am trying to import the following library:
import json2xml
from json2xml.utils import readfromstring
However, when I execute the second line I get this error:
Traceback (most recent call last):
File "C:\Users\denis\Desktop\Pazaruvaj Upload\Pazaruvaj_Part1_Test.py", line 12, in <module>
from json2xml.utils import readfromurl, readfromstring, readfromjson
File "C:\Python27\lib\site-packages\json2xml\utils.py", line 19
def readfromjson(filename: str) -> dict:
^
SyntaxError: invalid syntax
Couldn't find anything online about this issue.
Note I don't write from json2xml import json2xml because it gives the same error
According to https://pypi.org/project/json2xml/, json2xml is not compatible with Python2.
Python2 is deprecated, please update to Python3. Then this library should work.
I am using the PyYAML-3.10 as part of a Python program on macOS 10, using Python version 2.7.10. I am not able to make sense of these compilation errors. Since PyYAML-3.10 is a stable version of PyYAML, it should give no compilation errors. The errors are listed below. Any suggestions would be appreciated.
File "pyR#TE.py", line 3, in <module>
import yaml
File "/Users/PyR#TE/pyrate-1.0.0/yaml/__init__.py", line 8, in <module>
from .loader import *
File "/Users/PyR#TE/pyrate-1.0.0/yaml/loader.py", line 4, in <module>
from .reader import *
File "/Users/PyR#TE/pyrate-1.0.0/yaml/reader.py", line 45, in <module>
class Reader(object):
File "/Users/PyR#TE/pyrate-1.0.0/yaml/reader.py", line 137, in Reader
NON_PRINTABLE = re.compile('[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
raise error, v # invalid expression
sre_constants.error: bad character range
It seems that PyYAMP-3.10 is not compatible with Python 2. (Did you mean "PyYAML", by the way? I could not find a reference to a "PyYAMP" package anywhere.) The compilation error you are seeing is from re.compile - when Python is trying to compile a regular expression.
I tried using the line in your error message containing re.compile in Python 2 and Python 3.
Python 2:
>>> import re
>>> re.compile('[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/re.py", line 194, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.7/re.py", line 251, in _compile
raise error, v # invalid expression
sre_constants.error: bad character range
>>>
Python 3:
>>> import re
>>> re.compile('[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
re.compile('[^\t\n\r -~\x85\xa0-\ud7ff\ue000-�]')
>>>
So your options are either to find a package that supports Python 2, or to upgrade your code to Python 3. I recommend upgrading, as Python 2 is no longer supported.
I would like to embed python into a C application. Specifically, I would like to use sympy as part of the python portion. To accomplish this I created a clean install of anaconda. Here is a minimal working example that illustrates my problem.
int main()
{
putenv("PYTHONHOME=../anaconda3/bin/python3.7m");
Py_SetPath(L"../:../anaconda3/lib/python3.7:../anaconda3/lib/python3.7/lib-dynload:../anaconda3/lib/python3.7/site-packages:../anaconda3/lib/python3.7/site-packages/aeosa:../anaconda3/lib/python3.7/site-packages/IPython/extensions:../.ipython");
Py_Initialize();
//PyRun_SimpleString("import math\n");
PyRun_SimpleString("import sympy\n");
Py_FinalizeEx();
return (EXIT_SUCCESS)
}
This code compiles fine, but when I attempt to run it I get the following error.
Traceback (most recent call last):
File "../anaconda3/lib/python3.7/site-packages/sympy/__init__.py", line 19, in <module>
import mpmath
File "../anaconda3/lib/python3.7/site-packages/mpmath/__init__.py", line 5, in <module>
from .ctx_fp import FPContext
File "../anaconda3/lib/python3.7/site-packages/mpmath/ctx_fp.py", line 1, in <module>
from .ctx_base import StandardBaseContext
File "../anaconda3/lib/python3.7/site-packages/mpmath/ctx_base.py", line 3, in <module>
from .libmp.backend import xrange
File "../anaconda3/lib/python3.7/site-packages/mpmath/libmp/__init__.py", line 1, in <module>
from .libmpf import (prec_to_dps, dps_to_prec, repr_dps,
File "../anaconda3/lib/python3.7/site-packages/mpmath/libmp/libmpf.py", line 7, in <module>
import math
ImportError: dlopen(../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so, 2): Symbol not found: _PyExc_MemoryError
Referenced from: ../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so
Expected in: flat namespace
in ../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so
Looking at this error it appears that there is an error on "import math". Importing math by itself gives the following error confirming this.
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dlopen(../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so, 2): Symbol not found: _PyExc_MemoryError
Referenced from: ../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so
Expected in: flat namespace
in ../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so
I found several references where similar problems were encountered and discussed (e.g. this, this, this, and this), but the solutions have either not worked, weren't provided, or I didn't fully understand how they might relate to my problem. This solution suggested adding the following line before initialize may help
void*const libpython_handle = dlopen("libpython3.7m.dylib", RTLD_LAZY | RTLD_GLOBAL); // update to my python version
I also tried
void*const libpython_handle = dlopen("../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so", RTLD_LAZY | RTLD_GLOBAL);
as this specifically is (apparently) what's causing the problem. Neither worked. It appears that the problem is related to dependency problems with lib-dynload/* files (discussed here), but thus far I have not been able to find a workaround.
How might I fix this problem?
Edit:
I am using MacOS
Im getting this error when starting my software i dont know how to repair this
Traceback (most recent call last):
File "/root/findex/lib/python3.5/site-packages/findex_gui/main.py", line 208, in web
run_async()
File "/root/findex/lib/python3.5/site-packages/findex_gui/main.py", line 201, in run_async
from findex_gui.web import app
File "/root/findex/lib/python3.5/site-packages/findex_gui/web.py", line 41, in <module>
from findex_gui.orm.connect import Database
File "/root/findex/lib/python3.5/site-packages/findex_gui/orm/connect.py", line 12, in <module>
from findex_gui.orm.models import BASE
File "/root/findex/lib/python3.5/site-packages/findex_gui/orm/models.py", line 22, in <module>
from findex_common.utils import rand_str
ImportError: cannot import name 'rand_str'
I'm not familiar with the libraries in question, but it seems the maintainer renamed this function in 0.15.14 of findex-common here: development
This has been adjusted for in findex-gui on the master branch though it seems it has not seen a release. Here's the commit which fixes the import: Forgot what I was doing - Ill just push it all ¯_(ツ)_/¯
One short term fix would be to downgrade to findex-common==0.15.13 and perhaps follow up by raising an issue on either project since the change seems non-ideal.
I am trying to use PyQt's Resource System but it appears I have no clue what I am doing! I already have to application created, along with its GUI I am just trying to import some images to use with the program.
I used the QtDesigner to create the resource file and I compiled it using pyrcc4.exe. But when I attempt to import the resource file I get this error:
Traceback (most recent call last):
File "C:\Projects\main.py", line 14, in <module>
import main_rc
File "C:\Projects\main_rc.py", line 482, in <module>
qInitResources()
File "C:\Projects\main_rc.py", line 477, in qInitResources
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
TypeError: argument 2 of qRegisterResourceData() has an invalid type
What am I doing wrong?
pyrcc generates Python 2.x code by default.
Try regenerating your resource files using pyrcc with flag '-py3'