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.
Related
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
[joepareti54#xxx build]$ ./manta ../scenes/_trainingData.py --dim 3 --addModelGeometry True --addSphereGeometry True
Version: mantaflow 64bit fp1 commit dd3bb0c0a65cc531d3c33487bde5edcb4aa6784f from Mar 14 2018, 14:53:44
Loading script '../scenes/_trainingData.py'
Traceback (most recent call last):
File "../scenes/_trainingData.py", line 12, in <module>
from Emitter import *
File "/home/joepareti54/FluidNet/manta/scenes/Emitter.py", line 15, in <module>
import matlabnoise
File "/home/joepareti54/FluidNet/manta/build/../../../matlabnoise/matlabnoise.py", line 81
def Perlin2D(*args) -> "double" :
^
SyntaxError: invalid syntax
I believe the invalid syntax occurs in:
def Perlin2D(*args) -> "double" :`enter code here`
return _matlabnoise.Perlin2D(*args)
Perlin2D = _matlabnoise.Perlin2D
Your problem is that mantaflow is running an embedded Python, so the version used is the one that was available when mantaflow was compiled and it appears that version does not support the type annotations introduced in Python 3.5
When you run which python that shows you the version of Python installed on your system, not the version compiled into the other program.
Solutions include recompiling mantaflow with a more recent Python, or stop using type annotations.
I'm trying to use the following package: https://github.com/Anorov/cloudflare-scrape/blob/master/cfscrape/init.py
I have the following test file:
import cfscrape
import sys
import execjs
who = sys.argv[1]
scraper = cfscrape.create_scraper()
print scraper.get(who).content
Which is outputting the following error:
Traceback (most recent call last): File "test.py", line 1, in import cfscrape File "build/bdist.macosx-10.10-intel/egg/cfscrape/__init__.py", line 17, in EnvironmentError: Your Javascript runtime 'JavaScriptCore' is not supported due to security concerns. Please use Node.js, V8, or PyV8.
Can anyone point me in the right direction to change my JS_ENGINE from JavaScriptCore to NodeJs
I have installed scons 2.3.2 and have python 2.4.
When I run scons, I am seeing the following error:
scons
Import failed. Unable to find SCons files in:
/usr/bin/../engine
/usr/bin/scons-local-2.3.2
/usr/bin/scons-local
/usr/lib/scons-2.3.2
/usr/lib/scons-2.3.2
/usr/local/lib/scons-2.3.2
/usr/lib/python2.4/site-packages/scons-2.3.2
/usr/lib/python2.4/site-packages/scons-2.3.2
/usr/local/lib/python2.4/site-packages/scons-2.3.2
/usr/lib64/scons-2.3.2
/usr/lib/scons
/usr/lib/scons
/usr/local/lib/scons
/usr/lib/python2.4/site-packages/scons
/usr/lib/python2.4/site-packages/scons
/usr/local/lib/python2.4/site-packages/scons
/usr/lib64/scons
Traceback (most recent call last):
File "/usr/bin/scons", line 190, in ?
import SCons.Script
File "/usr/lib/scons/SCons/Script/__init__.py", line 76, in ?
import SCons.Environment
File "/usr/lib/scons/SCons/Environment.py", line 48, in ?
import SCons.Defaults
File "/usr/lib/scons/SCons/Defaults.py", line 52, in ?
import SCons.Tool
File "/usr/lib/scons/SCons/Tool/__init__.py", line 50, in ?
import SCons.Scanner.C
File "/usr/lib/scons/SCons/Scanner/C.py", line 36, in ?
import SCons.cpp
File "/usr/lib/scons/SCons/cpp.py", line 398
p = self.stack[-1] if self.stack else self.default_table
^
SyntaxError: invalid syntax
I did a find and found that SCons is present in /usr/lib/scons. I am not sure why scons is not able to pick it up.
What am I missing?
The problem (from the bottom of the traceback) is a Syntax error:
p = self.stack[-1] if self.stack else self.default_table
^
SyntaxError: invalid syntax
This is because you are running a version of Python that doesn't support conditional expressions:
Support for this syntax was added in 2.5, see the docs
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.