Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with the circular import #228

Open
IvanKhanas opened this issue Feb 14, 2025 · 4 comments
Open

Problem with the circular import #228

IvanKhanas opened this issue Feb 14, 2025 · 4 comments
Assignees

Comments

@IvanKhanas
Copy link

the code does not pass the tests (pytest) when building the rpm package, the following error is presented when passing the %check section

Image

Also, when opening a project in the IDE (VS Code) and trying to run project, we see the same error ...

Image

Judging by the error in the screenshot, the problem is circular import. The error occurs when trying to import dicttoxml from the json2xml module.

Please fix this bug ;)

@vinitkumar
Copy link
Owner

@IvanKhanas Can you please provide more info as to how to reproduce this issue? You said RPM package? Did you install it on Fedora. Please let me know so that I can look into it and if there is an issue, then potentially fix it.

@vinitkumar
Copy link
Owner

@IvanKhanas Also, One issue I can already spot is that you are trying to run it on Python 3.9. The latest version is only supported on Python 3.10 and above. Can you try running it on Python3.10 and above and report back, please?

@IvanKhanas
Copy link
Author

Image

I am building an RPM package from your project for ALT linux

Here are the error logs from the IDE, I'm not very good at Python, but chatGPt gives the following explanation:

The error you are encountering is caused by a circular import in Python. The error message states:

ImportError: cannot import name 'dicttoxml' from partially initialized module 'json2xml' (most likely due to a circular import)
Possible Causes:
The file name is the same as the module name
Your file is named json2xml.py, and it tries to import dicttoxml from the json2xml module. However, since Python first looks for modules in the current directory, it finds json2xml.py (the current file) instead of the actual module, which is not yet fully initialized.

Circular Import
In json2xml.py, you have the following import:

from json2xml import dicttoxml
If dicttoxml.py also imports json2xml, this creates a circular dependency.

Possible Solutions:

  1. Rename json2xml.py
    Try renaming your file json2xml.py to something else, such as:

json_to_xml.py
Then, try running the code again.

  1. Check Imports
    Open dicttoxml.py and make sure it does not import json2xml, as this could cause a circular import.
    If the import is necessary, move it inside a function instead of placing it at the top of the file.
  2. Use Explicit Package Import
    If json2xml is a package with an init.py file, try changing your import to:

from .dicttoxml import dicttoxml

@vinitkumar
Copy link
Owner

Thanks for your explanation @IvanKhana. Could you please once ensure that you are definitely running Python greater than Python 3.10 or above while trying to package it? I will also try to check this issue on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants