0

Running this code:

import feedparser

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

I get this error:

AttributeError: partially initialized module 'feedparser' has no attribute '__version__' (most likely due to a circular import)

I'm using Idle on a Mac, but I get the same error running in Terminal.

3
  • 1
    Do you have your own file named feedparser.py? Don't use the same name as a library module.
    – Barmar
    Commented Jan 12, 2023 at 16:57
  • filename is rss_feed.py
    – ghulseman
    Commented Jan 12, 2023 at 17:09
  • If that were the problem it would say that it can't find the library.
    – Barmar
    Commented Jan 12, 2023 at 17:15

1 Answer 1

1

I cannot reproduce your symptom.

Using feedparser 6.0.10 under cPython 3.10.8 and macos 12.6.2 your 1st print says:

<!-- 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>

and your 2nd print says

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

Use $ python -m site to verify that sys.path points to where you think it should, and that you've installed just a single feedparser library there. Consider nuking your venv and doing pip installs from scratch.

It is possible that you showed us just an excerpt from a larger codebase. Read your posted question and try to reproduce the symptom -- copy-n-paste those few lines of code into a new file and run that. Or use example code from the docs, which is very similar. It sounds like your install can't even support $ python -c 'import feedparser' yet.

6
  • I get same AttributeError error even if the only line in the file is "import feedparser". But when I enter import feedparser directly into the Idle shell, there's no error. Although entering other lines of the code result in assorted errors. If I enter Feed.keys(), I get the following output: dict_keys(['bozo', 'entries', 'feed', 'headers', 'bozo_exception'])
    – ghulseman
    Commented Jan 12, 2023 at 19:01
  • 1
    You have two environments where you're using feedparser: IDE and command line. One of them is working. We want to know what's different about them, so we can fix the broken one. Are you running the same interpreter in each? If . dot is in your PYTHONPATH env var, then the value of os.getcwd() is relevant. And sys.path controls the behavior of import. In each environment, write sys.path out to a text file. Compare those files, perhaps using $ diff -u. Post your analysis.
    – J_H
    Commented Jan 12, 2023 at 19:08
  • Can you be more specific about how to compare the two environments? I'm not very experienced with this stuff. My pip install of feedparser was through the correct file path to where Idle is installed on my Mac. I have installed numerous other libraries to Idle with no problems like this. I'm running Python 3.10.2 in Idle. Is there a way to determine which version of feedparser is installed?
    – ghulseman
    Commented Jan 12, 2023 at 19:17
  • Did you nuke your venv and pip install it again from scratch?
    – J_H
    Commented Jan 12, 2023 at 19:40
  • 1
    Start with $ which python to understand where the interpreter is coming from. Often there's more than one interpreter, each with its own set of installed importable libraries. I reported this triple to you: (feedparser 6.0.10, cPython 3.10.8, macos 12.6.2). Report the same triple for both environments, one working and one broken. I used conda with the pip install, so I obtained "6.0.10" from $ conda list | grep feedparser. Sometimes I will use poetry: $ poetry show | grep .... Maybe you're looking for $ pip list | grep .... Verify that .../python3.10/site-packages has what you expect.
    – J_H
    Commented Jan 12, 2023 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.