通过PIP安装bibtexparser模块不完整

1 投票
1 回答
938 浏览
提问于 2025-04-20 00:10

我一直在尝试用bibtexparser这个模块来解析一些BibTeX记录,但即使使用在bibtexparser文档中找到的示例代码,我也无法让它正常工作。

这段代码是:

import bibtexparser

bibtex = """@ARTICLE{Cesar2013,
author = {Jean César},
title = {An amazing title},
year = {2013},
month = jan,
volume = {12},
pages = {12--23},
journal = {Nice Journal},
abstract = {This is an abstract. This line should be long enough to test
multilines...},
comments = {A comment},
keywords = {keyword1, keyword2}
}
"""

with open('bibtex.bib', 'w') as bibfile:
    bibfile.write(bibtex)

with open('bibtex.bib') as bibtex_file:
    bibtex_str = bibtex_file.read()

bib_database = bibtexparser.loads(bibtex_str)
print(bib_database.entries)

出现的错误是:

Traceback (most recent call last):
  File "path-to-script...", line 12, in <module>
    bib_database = bibtexparser.loads(bibtex_str)
AttributeError: 'module' object has no attribute 'loads'

此外,当我尝试列出bibtexparser的属性时,发现“load”和“loads”这两个方法不在里面:

dir(bibtexparser)
['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'bparser', 'bwriter', 'customization', 'info', 'latexenc']

谢谢你的时间。

1 个回答

0

这个pip的版本其实没有问题(在新版本发布之前也是如此)。发帖的人提到的文档版本和他安装的版本不一致。

撰写回答