I have a xml str which encoding header declare as gb2312, I want to parse it with lxml.parse and use xpath to get value, the xml str content contain unicode character, currently my works as below:
from lxml import etree
from io import BytesIO
xml_data = """<?xml version="1.0" encoding="GB2312"?>
<CHARGEINFO>
<ITEM>
<DETAILEDCHARGESID>5E8C4E14E9C711EBB56E00155D96E1E0</DETAILEDCHARGESID>
<UNIT>元</UNIT>
<CHARGENUM>1</CHARGENUM>
<CHARGEDATE>2021-07-13 14:18:47</CHARGEDATE>
<CHARGESTATE>0</CHARGESTATE>
</ITEM>
</CHARGEINFO>"""
xml_root = etree.parse(BytesIO(xml_data.encode())).getroot()
xml_root.xpath("/CHARGEINFO/ITEM")
the output error is :
Traceback (most recent call last):
File "/Users/gui/Documents/workspace/PIS_middle_layer/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3441, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-11-527d4b9dab58>", line 14, in <module>
xml_root = etree.parse(BytesIO(xml_data.encode())).getroot()
File "src/lxml/etree.pyx", line 3521, in lxml.etree.parse
File "src/lxml/parser.pxi", line 1876, in lxml.etree._parseDocument
File "src/lxml/parser.pxi", line 1896, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1784, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1141, in lxml.etree._BaseParser._parseDoc
File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
File "<string>", line 1
XMLSyntaxError: switching encoding: encoder error, line 1, column 38
Is there any better way to parse this xml data?
You've declared the XML to be encoded in gb2312, but BytesIO(xml_data.encode()) defaults to encoding in utf8, hence the "switching encoding" error. The declaration and the encoding of the data need to agree.
Change the xml_root assignment line to:
xml_root = etree.parse(BytesIO(xml_data.encode('gb2312'))).getroot()
OR change the xml_data assignment line to:
xml_data = """<?xml version="1.0" encoding="UTF-8"?>
This is the error and I've already reset the server, compiler and remove all .pyc files and there is no typo error. architect_ids is present in the module and also imported in init.py. Still, the error is that it won't recognize or it cannot read the field "architect_ids". depends are already in place. I don't know how to resolve this.
Error:
Odoo Server Error
Traceback (most recent call last):
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 392, in _check_xml
self.postprocess_and_fields(view.model, view_doc, view.id)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 952, in postprocess_and_fields
fields_def = self.postprocess(model, node, view_id, False, fields)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 882, in postprocess
fields.update(self.postprocess(model, f, view_id, in_tree_view, model_fields))
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 882, in postprocess
fields.update(self.postprocess(model, f, view_id, in_tree_view, model_fields))
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 882, in postprocess
fields.update(self.postprocess(model, f, view_id, in_tree_view, model_fields))
[Previous line repeated 1 more time]
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 803, in postprocess
xarch, xfields = self.with_context(
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 964, in postprocess_and_fields
self.raise_view_error(message, view_id)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 592, in raise_view_error
raise ValueError(message)
ValueError: Field `architect_ids` does not exist
Error context:
View `architect.page.view`
[view_id: 849, xml_id: n/a, model: sale.order, parent_id: 756]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 712, in parse
self._tag_root(de)
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 674, in _tag_root
f(rec)
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 577, in _tag_record
record = model._load_records([data], self.mode == 'update')
File "D:\dev\odoo-13.0\odoo\models.py", line 4067, in _load_records
records = self._load_records_create([data['values'] for data in to_create])
File "D:\dev\odoo-13.0\odoo\models.py", line 3981, in _load_records_create
return self.create(values)
File "<decorator-gen-32>", line 2, in create
File "D:\dev\odoo-13.0\odoo\api.py", line 336, in _model_create_multi
return create(self, arg)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 473, in create
return super(View, self).create(vals_list)
File "<decorator-gen-3>", line 2, in create
File "D:\dev\odoo-13.0\odoo\api.py", line 336, in _model_create_multi
return create(self, arg)
File "D:\dev\odoo-13.0\odoo\models.py", line 3762, in create
fields[0].determine_inverse(batch_recs)
File "D:\dev\odoo-13.0\odoo\fields.py", line 1114, in determine_inverse
getattr(records, self.inverse)()
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 299, in _inverse_arch
view.write(data)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 490, in write
return super(View, self).write(self._compute_defaults(vals))
File "D:\dev\odoo-13.0\odoo\models.py", line 3551, in write
real_recs._validate_fields(set(vals) - set(inverse_fields))
File "D:\dev\odoo-13.0\odoo\models.py", line 1167, in _validate_fields
check(self)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 394, in _check_xml
raise ValidationError("%s\n\n%s" % (_("Error while validating view"), tools.ustr(e)))
odoo.exceptions.ValidationError: ('Error while validating view\n\nField `architect_ids` does not exist\n\nError context:\nView `architect.page.view`\n[view_id: 849, xml_id: n/a, model: sale.order, parent_id: 756]', None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\dev\odoo-13.0\odoo\http.py", line 619, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "D:\dev\odoo-13.0\odoo\http.py", line 309, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "D:\dev\odoo-13.0\odoo\tools\pycompat.py", line 14, in reraise
raise value
File "D:\dev\odoo-13.0\odoo\http.py", line 664, in dispatch
result = self._call_function(**self.params)
File "D:\dev\odoo-13.0\odoo\http.py", line 345, in _call_function
return checked_call(self.db, *args, **kwargs)
File "D:\dev\odoo-13.0\odoo\service\model.py", line 93, in wrapper
return f(dbname, *args, **kwargs)
File "D:\dev\odoo-13.0\odoo\http.py", line 338, in checked_call
result = self.endpoint(*a, **kw)
File "D:\dev\odoo-13.0\odoo\http.py", line 910, in __call__
return self.method(*args, **kw)
File "D:\dev\odoo-13.0\odoo\http.py", line 510, in response_wrap
response = f(*args, **kw)
File "d:\dev\odoo-13.0\addons\web\controllers\main.py", line 1324, in call_button
action = self._call_kw(model, method, args, kwargs)
File "d:\dev\odoo-13.0\addons\web\controllers\main.py", line 1312, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "D:\dev\odoo-13.0\odoo\api.py", line 387, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "D:\dev\odoo-13.0\odoo\api.py", line 374, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-59>", line 2, in button_immediate_install
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_module.py", line 72, in check_and_log
return method(self, *args, **kwargs)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_module.py", line 463, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_module.py", line 573, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "D:\dev\odoo-13.0\odoo\modules\registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "D:\dev\odoo-13.0\odoo\modules\loading.py", line 421, in load_modules
processed_modules += load_marked_modules(cr, graph,
File "D:\dev\odoo-13.0\odoo\modules\loading.py", line 313, in load_marked_modules
loaded, processed = load_module_graph(
File "D:\dev\odoo-13.0\odoo\modules\loading.py", line 225, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package, report=report)
File "D:\dev\odoo-13.0\odoo\modules\loading.py", line 68, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 736, in convert_file
convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 803, in convert_xml_import
obj.parse(doc.getroot())
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 715, in parse
pycompat.reraise(
File "D:\dev\odoo-13.0\odoo\tools\pycompat.py", line 13, in reraise
raise value.with_traceback(tb)
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 712, in parse
self._tag_root(de)
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 674, in _tag_root
f(rec)
File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 577, in _tag_record
record = model._load_records([data], self.mode == 'update')
File "D:\dev\odoo-13.0\odoo\models.py", line 4067, in _load_records
records = self._load_records_create([data['values'] for data in to_create])
File "D:\dev\odoo-13.0\odoo\models.py", line 3981, in _load_records_create
return self.create(values)
File "<decorator-gen-32>", line 2, in create
File "D:\dev\odoo-13.0\odoo\api.py", line 336, in _model_create_multi
return create(self, arg)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 473, in create
return super(View, self).create(vals_list)
File "<decorator-gen-3>", line 2, in create
File "D:\dev\odoo-13.0\odoo\api.py", line 336, in _model_create_multi
return create(self, arg)
File "D:\dev\odoo-13.0\odoo\models.py", line 3762, in create
fields[0].determine_inverse(batch_recs)
File "D:\dev\odoo-13.0\odoo\fields.py", line 1114, in determine_inverse
getattr(records, self.inverse)()
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 299, in _inverse_arch
view.write(data)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 490, in write
return super(View, self).write(self._compute_defaults(vals))
File "D:\dev\odoo-13.0\odoo\models.py", line 3551, in write
real_recs._validate_fields(set(vals) - set(inverse_fields))
File "D:\dev\odoo-13.0\odoo\models.py", line 1167, in _validate_fields
check(self)
File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 394, in _check_xml
raise ValidationError("%s\n\n%s" % (_("Error while validating view"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating view
Field `architect_ids` does not exist
Error context:
View `architect.page.view`
[view_id: 849, xml_id: n/a, model: sale.order, parent_id: 756]
None" while parsing file:/d:/dev/odoo-13.0/custom/architect_page/views/architect_page.xml:1, near
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">architect.page.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//page[#name='order_lines']" position="after">
<page string="Architect and Interior Designer">
<field name="architect_ids">
<tree string="Architect and Interior Designer" editable="bottom">
<control>
<create name="add_architect_control" string="Add a architect"/>
</control>
<field name="architect_ids"/>
<field name="architect_commission"/>
<field name="architect_com_type"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
</odoo>
These are my models:
architectpage.py
from odoo import models, fields
class ArchitectPage(models.Model):
_inherit = 'sale.order'
architect_ids = fields.One2many(string='Architect',
comodel_name='res.architect', inverse_name='sale_id')
res_architect.py
from odoo import models, fields, api, exceptions
class ResArchitect(models.Model):
_name = 'res.architect'
name = fields.Char('name')
architect_com_type = fields.Selection(string='Commission type',
selection=[('percentage', 'Percentage'), ('float', 'Float')])
architect_commission = fields.Float(string='Architect Commission')
sale_id = fields.Many2one(string='sale', comodel_name='sale.order')
# put your constraint here
#api.constrains('architect_com_type', 'architect_commission')
def _validate_commission(self):
for field in self:
if field.architect_com_type == 'Percentage':
if (field.architect_com_type > 100) or (field.architect_com_type <= 0):
raise exceptions.ValidationError(
"Percentage fields must be less than equal to 100 or greater than 0")
xml:
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">architect.page.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//page[#name='order_lines']" position="after">
<page string="Architect and Interior Designer">
<field name='architect_ids'>
<tree string="Architect and Interior Designer"
editable="bottom">
<control>
<create name="add_architect_control" string="Add a architect"/>
</control>
<field name="architect_ids"/>
<field name="architect_commission"/>
<field name="architect_com_type"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
</odoo>
other custom modules:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class architect(models.Model):
_name = 'architect.form'
_description = 'architect'
prefix_id = fields.Selection(
[('company', 'COMPANY'), ('architect', 'ARCH'), ('interior designer', 'ID'), ('others', 'OTHERS')],
required=True)
first_name = fields.Char(string="First Name", required=True)
last_name = fields.Char(string="Last Name", required=True)
address = fields.Char(string="Address", required=True)
email = fields.Char(string="Email")
mobile_no = fields.Char(string="Mobile No.")
tel_no = fields.Char(string="Telephone No.")
Remove
architect_ids
from tree view
<field name='architect_ids'>
<tree string="Architect and Interior Designer"
editable="bottom">
<control>
<create name="add_architect_control" string="Add a architect"/>
</control>
<!-- Removing architect_ids from view -->
<!-- <field name="architect_ids"/> -->
<field name="architect_commission"/>
<field name="architect_com_type"/>
</tree>
</field>
On your model['sale.order'] view there is architect_ids field [One2many] defined.
On your XML file, you have added that One2many field from there you have add the unwanted field architect_ids which is not on that model you are accessing ['res.architect'].
Check here,
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">architect.page.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="XML">
<xpath expr="//page[#name='order_lines']" position="after">
<page string="Architect and Interior Designer">
<field name='architect_ids'>
<tree string="Architect and Interior Designer"
editable="bottom">
<control>
<create name="add_architect_control" string="Add a architect"/>
</control>
<field name="architect_commission"/>
<field name="architect_com_type"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
</odoo>
Thanks
I'm on chapter 11 of the official guide to the open62541 library. The html version is here. Before trying anything custom, I just want to try this feature in the most basic way by "compiling" their example xml file into C code, which can then be compiled with the GCC and run as an OPC server. (If you would like to follow along, download the full source code from the main page—the nodeset compiler tool is in there.)
I'm in a Debian-based environment (CLI only). I made a copy of myNS.xml and saved it directly in the path ~/code/open62541-open62541-6249bb2/tools/nodeset_compiler/, which is also my current working directory in this example. I tried to use the nodeset compiler with exactly the same command that they use in the tutorial: python ./nodeset_compiler.py --types-array=UA_TYPES --existing ../../deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml --xml myNS.xml myNS
The error message I got is this:
Traceback (most recent call last):
File "./nodeset_compiler.py", line 126, in <module>
ns.addNodeSet(xmlfile, True, typesArray=getTypesArray(nsCount))
File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/nodeset.py", line 224, in addNodeSet
nodesets = dom.parseString(fileContent).getElementsByTagName("UANodeSet")
File "/usr/lib/python2.7/xml/dom/minidom.py", line 1928, in parseString
return expatbuilder.parseString(string)
File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 940, in parseString
return builder.parseString(string)
File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 223, in parseString
parser.Parse(string, True)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0
Any idea what I might be doing wrong?
UPDATE:
Alright, I found out there was a problem with my Opc.Ua.NodeSet2.xml file, which I corrected. If you are following along and would like to grab the version of the file I have, you can get it here.
But now I have this issue:
INFO:__main__:Preprocessing (existing) ../../deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
INFO:__main__:Preprocessing myNS.xml
Traceback (most recent call last):
File "./nodeset_compiler.py", line 178, in <module>
ns.allocateVariables()
File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/nodeset.py", line 322, in allocateVariables
n.allocateValue(self)
File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/nodes.py", line 291, in allocateValue
self.value.parseXMLEncoding(self.xmlValueDef, dataTypeNode, self)
File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 161, in parseXMLEncoding
val = self.__parseXMLSingleValue(el, parentDataTypeNode, parent)
File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 281, in __parseXMLSingleValue
extobj.value.append(extobj.__parseXMLSingleValue(ebodypart, parentDataTypeNode, parent, alias=None, encodingPart=e))
File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 223, in __parseXMLSingleValue
alias=alias, encodingPart=enc[1], valueRank=enc[2] if len(enc)>2 else None)
File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 198, in __parseXMLSingleValue
t.parseXML(xmlvalue)
File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 330, in parseXML
self.value = int(unicode(xmlvalue.firstChild.data))
ValueError: invalid literal for int() with base 10: ''
UPDATE_2:
I tried doing the same thing on my Windows laptop, and here is the error I got:
INFO:__main__:Preprocessing (existing) ../../deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
INFO:__main__:Preprocessing myNS.xml
Traceback (most recent call last):
File "./nodeset_compiler.py", line 178, in <module>
ns.allocateVariables()
File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\nodeset.py", line 322, in allocateVariables
n.allocateValue(self)
File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\nodes.py", line 291, in allocateValue
self.value.parseXMLEncoding(self.xmlValueDef, dataTypeNode, self)
File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 161, in parseXMLEncoding
val = self.__parseXMLSingleValue(el, parentDataTypeNode, parent)
File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 281, in __parseXMLSingleValue
extobj.value.append(extobj.__parseXMLSingleValue(ebodypart, parentDataTypeNode, parent, alias=None, encodingPart=e))
File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 223, in __parseXMLSingleValue
alias=alias, encodingPart=enc[1], valueRank=enc[2] if len(enc)>2 else None)
File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 198, in __parseXMLSingleValue
t.parseXML(xmlvalue)
File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 330, in parseXML
self.value = int(unicode(xmlvalue.firstChild.data))
ValueError: invalid literal for int() with base 10: '\n '
The complete documentation for the open62541 nodeset compiler can be found here:
https://open62541.org/doc/current/nodeset_compiler.html
The command you are using also seems to be fine.
The last issue you are describing invalid literal for int() is due to a newline inside the value tag of a variable.
This will be fixed with
https://github.com/open62541/open62541/pull/2768
For a workaround you can change your .xml from
<Value>
<Int32>
</Int32>
</Value>
to (no newline):
<Value>
<Int32></Int32>
</Value>
Hello I want to use the following package called textrank, see the following url for details:
https://github.com/davidadamojr/TextRank
After to clone all the dependencies with pip3, I tried to use this repository as follows:
textrank extract_summary test
However I got the following error:
MacBook-Pro:TextRank-master $ textrank extract_summary test
Traceback (most recent call last):
File "/usr/local/bin/textrank", line 11, in <module>
load_entry_point('textrank==0.1.0', 'console_scripts', 'textrank')()
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/main.py", line 21, in extract_summary
summary = textrank.extract_sentences(f.read())
File "/usr/local/lib/python3.6/site-packages/textrank/__init__.py", line 169, in extract_sentences
sent_detector = nltk.data.load('tokenizers/punkt/english.pickle')
File "/usr/local/lib/python3.6/site-packages/nltk/data.py", line 801, in load
opened_resource = _open(resource_url)
File "/usr/local/lib/python3.6/site-packages/nltk/data.py", line 919, in _open
return find(path_, path + ['']).open()
File "/usr/local/lib/python3.6/site-packages/nltk/data.py", line 641, in find
raise LookupError(resource_not_found)
LookupError:
**********************************************************************
Resource 'tokenizers/punkt/PY3/english.pickle' not found.
Please use the NLTK Downloader to obtain the resource: >>>
nltk.download()
Searched in:
- '/Users/ad/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- ''
**********************************************************************
It seems that there is a file of the nltk library that is missing, so I tried:
MacBook-Pro:TextRank-master adolfocamachogonzalez$ python3
Python 3.6.1 (default, Apr 4 2017, 09:40:21)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> nltk.download()
showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml
However I was not able to get the external resource, Since I tried copy and pasting the link into the browser but I got only like an xml structure as follows:
<?xml version="1.0"?>
<?xml-stylesheet href="index.xsl" type="text/xsl"?>
<nltk_data>
<packages>
<package checksum="d577c2cd0fdae148b36d046b14eb48e6" id="maxent_ne_chunker" languages="English" name="ACE Named Entity Chunker (Maximum entropy)" size="13404747" subdir="chunkers" unzip="1" unzipped_size="23604982" url="https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/chunkers/maxent_ne_chunker.zip" />
<package author="Australian Broadcasting Commission" checksum="ffb36b67ff24cbf7daaf171c897eb904" id="abc" name="Australian Broadcasting Commission 2006" size="1487851" subdir="corpora" unzip="1" unzipped_size="4054966" url="https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/corpora/abc.zip" webpage="http://www.abc.net.au/" />
<package checksum="ae529a1c5f13d6074f5b0d68d8edb537" contact="Gertjan van Noord" id="alpino" license="Distributed with permission of Gertjan van Noord" name="Alpino Dutch Treebank" size="2797255" subdir="corpora" unzip="1" unzipped_size="21604821" url="https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/corpora/alpino.zip" webpage="http://www.let.rug.nl/~vannoord/trees/" />
<package checksum="d3be36b53ab201372f1cd63ffc75e9a9" copyright="Public Domain (not copyrighted)" id="biocreative_ppi" license="Public Domain" name="BioCreAtIvE (Critical Assessment of Information Extraction Systems in Biology)" size="223566" subdir="corpora" unzip="1" unzipped_size="1537086" url="https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/corpora/biocreative_ppi.zip" webpage="http://www.mitre.org/public/biocreative/" />
<package author="W. N. Francis and H. Kucera" checksum="a0a8630959d3d937873b1265b0a05497" id="brown" license="May be used for non-commercial purposes." name="Brown Corpus" size="3314357" subdir="corpora" unzip="1" unzipped_size="10117565" url="https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/pa
The file english.pickle is part of the "punkt" tokenizer that breaks up text into sentences. To download it, run the following once (or find "punkt" in the interactive downloader, under Models).
nltk.download("punkt")
The downloader will check a list of standard paths for a location it can write to, and will save the model file there. After that it will be available to textrank's internals.