Fixing Circular Import Errors
A Quick write about using pyreverse to find circular import issues.

Hi, I’m a self-taught backend developer with 3+ years of experience, currently working at a tech startup based in The Bahamas. I mostly work with Python and Django, building APIs, designing database models, and improving performance when needed. I enjoy learning new tools and technologies as projects require.
alright, this is a quick write about the circular import error i faced recently. the project had so many files and imports and i knew it would end up like this someday but now when i saw import errors, i was procrastinating a lot since i was feeling too lazy to traverse so many to trace the issues. also i need to restructured the files again which again another challenge when u got so many files.
anyway i was exploring and i found this package pyreverse. it’s so easy to generate a mind map of imports.
use this cmd in root folder but make sure your project’s root folder have __init__.py file.
then run
pyreverse -o png .
this will need graphviz library to generate png images which u can install using apt or brew install graphviz but u can also use other format to export. check pyreverse docs for more details about different formats.
understanding this graph is simple too. the arrows should go upward and there shouldn’t be arrows pointing at each other. if they are pointing at each other, you probably already have circular import issues and errors will be shown when you run the code. but if error isn’t raised, still it’s a good idea to rethink about project imports as you’re close to circular import errors.





