I'm trying out AlchemyAPI_Python-0.6 - PyXml module. I was trying to run the keyword extractor feature of it, but got the following error when trying to compile. I used the keywords.py file given in the examples. I copied all the files underneath the python directory (AlchemyAPI.py, keywords.py, api_key.txt).
Traceback (most recent call last):
File "C:\Python26\keywords.py", line 4, in <module>
import AlchemyAPI
File "C:\Python26\AlchemyAPI.py", line 6, in <module>
from xml import xpath
File "C:\Python26\lib\site-packages\_xmlplus\xpath\__init__.py", line 112, in <module>
from pyxpath import ExprParserFactory
File "C:\Python26\lib\site-packages\_xmlplus\xpath\pyxpath.py", line 59, in <module>
from xml.xpath.ParsedAbbreviatedRelativeLocationPath import ParsedAbbreviatedRelativeLocationPath
File "C:\Python26\lib\site-packages\_xmlplus\xpath\ParsedAbbreviatedRelativeLocationPath.py", line 31
as = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self')
^
SyntaxError: invalid syntax
Can some one help me out with this issue, please?
Thank you in advance!
I work for AlchemyAPI.
We just revamped our Python SDK, removing dependencies on PyXML (if you're using Python 2.4 and earlier, you'll need lxml).
Please find the new SDK here: http://www.alchemyapi.com/tools/
It supports all versions of Python 2 and Python 3.
PyXML was written for Python 2.4, and the as keyword was introduced gradually in Python 2.5 and 2.6. In the last line of the stack trace above, the as keyword is used as a variable name, which conflicts with the syntax of Python 2.6.
You can solve this issue by editing two files, changing the name of the as variable to something else (e.g. axis):
C:\Python26\lib\site-packages\_xmlplus\xpath\ParsedAbbreviatedRelativeLocationPath.py, lines 31 and 32:
axis = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self')
self._middle = ParsedStep.ParsedStep(axis, nt, ppl)
C:\Python26\lib\site-packages\_xmlplus\xpath\ParsedAbbreviatedAbsoluteLocationPath.py, lines 27 and 28:
axis = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self')
self._step = ParsedStep.ParsedStep(axis, nt, ppl)
Related
When i run setup.py as a script i have no issues reading a parameter file.
When i build with pyinstaller and run the same script as a .exe i receive the below error.
>setup.exe
Traceback (most recent call last):
File "setup.py", line 106, in <module>
param_file_info = paramsfx.extract_param_file_info(param_text)
File "app\paramsfx.py", line 64, in extract_param_file_info
s_n = re.search(rc_n, param_file_text)
File "c:\users\xxxxxx\appdata\local\programs\python\python37-32\lib\re.py", line 183, in search
return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object
[21776] Failed to execute script setup
i have read up on other posts how to resolve this error however before changing the code (that is working fine as a script) i wanted to see if anyone had any thoughts as to why it read the parameter differently as a .exe.
Just from looking at this output and not the code I noticed this:
"TypeError: cannot use a string pattern on a bytes-like object"
If this is true, I would recommend doing some python type conversion. Here is a link to help you out
https://www.w3schools.com/python/trypython.asp?filename=demo_numbers_convert
Because I don't know how your code is structured, choosing which form of conversion you choose may affect your results so please be careful with that.
I hope my explanation could have provided some use to you.
I am not well versed in python... my professor posted a piece of code that includes the following lines:
def formatOptions(options):
from string import joinfields, strip, split
options = joinfields(map(strip, split(strip(options), '\n')), ':')
return options
When I run this using idle 2.7, I do not get an error message. But when I run it using python 3, I get an error message. Is this a difference in the two versions, or do I have a problem with the python 3 build? This is the error message:
File "ml_exercise.py", line 46, in <module>
formatOptions(options))
File "ml_exercise.py", line 28, in formatOptions
from string import joinfields, strip, split
ImportError: cannot import name 'joinfields'
string functions where already mostly deprecated (in favor of the str class methods) in Python 1.6.0 (that is some 18 years ago). The idiomatic way to write this code is
options = ':'.join(part.strip() for part in options.strip().splitlines())
joinfields removed from Python in version 3. Just use the string join function like:
options = ':'.join(map(strip, split(strip(options), '\n')))
I am trying to run the Wanish library in python and getting the following instead of the result expected.
>>> from wanish import Wanish
>>> wanish = Wanish()
>>> wanish.perform_url("http://www.bbc.com/news/uk-england-london-40269625")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python36\lib\site-packages\wanish-0.6.3-py3.6.egg\wanish\__init__.py", line 167, in perform_url
File "C:\Python36\lib\site-packages\wanish-0.6.3-py3.6.egg\wanish\summarizer.py", line 55, in get_plain_text
File "C:\Python36\lib\site-packages\wanish-0.6.3-py3.6.egg\wanish\summarizer.py", line 91, in create_referat
File "C:\Python36\lib\site-packages\wanish-0.6.3-py3.6.egg\wanish\summarizer.py", line 68, in textrank
File "C:\Python36\lib\site-packages\wanish-0.6.3-py3.6.egg\wanish\langid.py", line 175, in classify
File "C:\Python36\lib\site-packages\wanish-0.6.3-py3.6.egg\wanish\langid.py", line 148, in instance2fv
TypeError: 'float' object cannot be interpreted as an integer
I have tried this using Python 3.6 and even with python 2.7
I came across the same issues.
Actually if you visit pypi wanish page you will see that it located only in Python 3.x categories:
Programming Language :: Python
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
It won't work in Python 2 because in code there is from urllib.parse import urlparse, urljoin line. But from docs:
The urlparse module is renamed to urllib.parse in Python 3
The offending line is this one* in LanguageIdentifier.instance2fv():
arr = np.zeros((self.nb_numfeats,), dtype='uint32')
In LanguageIdentifier.from_modelstring(), the factory method used to instantiate this class, you can find this:
nb_numfeats = len(nb_ptc) / len(nb_pc)
In python3, division using the / operator always returns a float, where in python2 it returns an int if both operants are ints. So this is a bug.
The langid.py file seems to actually come from a different project, where this error was fixed a while ago.
*I would normally link to the code directly, but someone decided to drop a ~2.4MB blob of base64 in the source file, so github doesn't allow linking.
I am receiving the following error message when I try to read a Vensim model file (.mdl) using Python's PySD package.
My code is:
import pysd
import os
os.chdir('path/to/model_file')
model = pysd.read_vensim('my_model.mdl')
The Error I receive is:
Traceback (most recent call last):
Python Shell, prompt 13, line 1
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pysd/pysd.py", line 53, in read_vensim
py_model_file = translate_vensim(mdl_file)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pysd/vensim2py.py", line 673, in translate_vensim
entry.update(get_equation_components(entry['eqn']))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pysd/vensim2py.py", line 251, in get_equation_components
tree = parser.parse(equation_str)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/parsimonious/grammar.py", line 123, in parse
return self.default_rule.parse(text, pos=pos)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/parsimonious/expressions.py", line 110, in parse
node = self.match(text, pos=pos)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/parsimonious/expressions.py", line 127, in match
raise error
parsimonious.exceptions.ParseError: Rule 'subscriptlist' didn't match at '' (line 1, column 21).
I have searched for this particular error and I cannot find much information on the failed matching rule for 'subscriptlist'.
I appreciate any insight. Thank you.
Good news is that there is nothing wrong with your code. =) (Although you can also just include the path to the file in the .read_vensim call, if you don't want to make the dir change).
That being the case, there are a few possibilities that would cause this issue. One is if the model file is created with a sufficiently old version of Vensim, the syntax may be different from what the current parser is designed for. One way to get around this is to update Vensim and reload the model file there - Vensim will update to the current syntax.
If you are already using a recent version of Vensim (the parser was developed using syntax of Vensim 6.3E) then the parsing error may be due to a feature that isn't yet included. There are still some outstanding issues with subscripts, which you can read about here and here).
If you aren't using subscripts, you may have found a bug in the parser. If so, best course is to create a report in the github issue tracker for the project. The stack trace you posted says that the error is happening in the first line of the file, and that the error has to do with how the right hand side of the equation is being parsed. You might include the first few lines in your bug report to help me recreate the issue. I'll add a case to our growing test suite and then we can make sure it isn't a problem going forwards.
I'm newbie to programming python. I built Beremiz program on Linux, I got this error.
File "Beremiz.py", line 164, in <module>
from ProjectController import ProjectController, MATIEC_ERROR_MODEL, ITEM_CONFNODE
File "/DATA1/UTILITY/Beremiz/beremiz/ProjectController.py", line 16, in <module>
import connectors
File "/DATA1/UTILITY/Beremiz/beremiz/connectors/__init__.py", line 34
for name in listdir(_base_path)
^
connectors = {name:_GetLocalConnectorClassFactory(name)
for name in listdir(_base_path)
if path.isdir(path.join(_base_path, name))
and not name.startswith("__")}
This syntax is not build of python. What is problem?
Thanks for all.
You need to make sure that your version of Python supports the dictionary comprehension syntax. This requires Python >= 2.7 or Python >= 3.
Otherwise you can modify the code like this:
connectors = dict((name, _GetLocalConnectorClassFactory(name))
for name in listdir(_base_path)
if path.isdir(path.join(_base_path, name))
and not name.startswith("__"))