Python rss提要获得AttributeError



运行此代码:

import feedparser
Feed = feedparser.parse('http://www.reddit.com/r/python/.rss')
pointer = Feed.entries[1]
print (pointer.summary)
print (pointer.link)

我得到这个错误:

AttributeError:部分初始化模块'feedparser'没有属性'__version__'(很可能是由于循环导入)

我在Mac上使用Idle,但在Terminal中运行时得到相同的错误。

我无法重现您的症状。

在cPython 3.10.8和macos 12.6.2下使用feedparser 6.0.10,你的第一个打印结果是:

<!-- SC_OFF --><div class="md"><p>Discussion of using Python in a professional environment, getting jobs in Python as well as ask questions about courses to further your python education!</p> <p><strong>This thread is not for recruitment, please see</strong> <a href="https://www.reddit.com/r/PythonJobs">r/PythonJobs</a> <strong>or the thread in the sidebar for that.</strong></p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Im__Joseph"> /u/Im__Joseph </a> <br /> <span><a href="https://www.reddit.com/r/Python/comments/109k9to/thursday_daily_thread_python_careers_courses_and/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/Python/comments/109k9to/thursday_daily_thread_python_careers_courses_and/">[comments]</a></span>

而你的第二个字写着

https://www.reddit.com/r/Python/comments/109k9to/thursday_daily_thread_python_careers_courses_and/

使用$ python -m site验证sys.path指向你认为应该指向的地方,并且您只安装了一个feed解析器图书馆在那里。考虑把你的venv和从头开始安装PIP

有可能你给我们看的只是摘录从更大的代码库。阅读你发布的问题试着重现症状,复制-粘贴将这几行代码放入一个新文件中,然后运行它。或使用来自的示例代码的文档,非常相似。听起来你的安装甚至不能支持$ python -c 'import feedparser'

最新更新