Python Forum
What is a circular import? asked by a newbie of newbies - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: What is a circular import? asked by a newbie of newbies (/thread-38212.html)



What is a circular import? asked by a newbie of newbies - ineuw - Sep-16-2022

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



RE: What is a circular import? asked by a newbie of newbies - Gribouillis - Sep-16-2022

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.