Python Forum

Full Version: What is a circular import? asked by a newbie of newbies
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Using Linux Mint Cinnamon 21.0, I want to parse my bookmarks.html file with a script from https://pypi.org/project/bookmarks-parser/.

#! /usr/bin/python3

import pprint
import bookmarks_parser

bookmarks = bookmarks_parser.parse("bookmarks.html")
pprint.pprint(bookmarks)
Pasted the script into the Python terminal, line by line, with the following results.

ineuw@lmc210dt:~/Desktop$ python3
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
>>>  import pprint
>>>  import bookmarks_parser

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ineuw/Desktop/bookmarks_parser.py", line 6, in <module>
    bookmarks = bookmarks_parser.parse("bookmarks.html")
AttributeError: partially initialized module 'bookmarks_parser' has no attribute 'parse' (most likely due to a circular import)
>>> 
It is likely that you have a file named bookmarks_parser.py . Try this command to see where Python imports bookmarks_parser from
Output:
python3 -c "import bookmarks_parser; print(bookmarks_parser)"
EDIT: sorry the information was in your traceback:
Quote:File "/home/ineuw/Desktop/bookmarks_parser.py", line 6, in <module>
Rename the file to something else. It is not the module that Python must import.