Python Forum
What is a circular import? asked by a newbie of newbies
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is a circular import? asked by a newbie of newbies
#1
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)
>>> 
Linux Mint Cinnamon 21.3 - Python 3.10.12 - Autokey-gtk 0.96.0 as of 2024-01-13.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Circular Import Led_Zeppelin 3 2,661 Jul-14-2021, 07:41 PM
Last Post: snippsat
  help on pandas circular import jip31 2 8,398 May-18-2021, 11:54 AM
Last Post: jip31
  Circular import dependency hobbyist 9 3,887 Feb-23-2021, 11:57 AM
Last Post: Gribouillis
  IP Subnet is asked from user Mahmut 1 1,965 Mar-08-2019, 10:10 AM
Last Post: Larz60+
  Lists in list for newbies LedDiode 4 3,148 Dec-25-2018, 09:48 AM
Last Post: LedDiode
  Robot Stay Inside Circular Ring webmanoffesto 4 6,691 Dec-07-2016, 06:57 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020