Help with Python circular error

Chris Angelico rosuav at gmail.com
Tue Jun 15 13:29:57 EDT 2021


On Wed, Jun 16, 2021 at 3:17 AM MRAB <python at mrabarnett.plus.com> wrote:
>
> On 2021-06-15 17:49, Chris Angelico wrote:
> > On Wed, Jun 16, 2021 at 2:45 AM Arak Rachael <arakelthedragon at gmail.com> wrote:
> >>
> >> Hi to everyone,
> >>
> >> I am having a problem with this error, I created a package and uploaded it to Test PyPi, but I can not get it to work, can someone help me please?
> >>
> >> https://test.pypi.org/manage/project/videotesting/releases/'
> >>
> >> The error:
> >>
> >> /home/user/anaconda3/envs/testing/bin/python /home/user/devel/python.assignments/topgis-viz/topgis-test.py
> >> Traceback (most recent call last):
> >>   File "/home/user/devel/python.assignments/topgis-viz/topgis-test.py", line 10, in <module>
> >>     from videotesting import downsample_and_save_npz
> >>   File "/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py", line 7, in <module>
> >>     from videotesting import extract_video
> >> ImportError: cannot import name 'extract_video' from partially initialized module 'videotesting' (most likely due to a circular import) (/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py)
> >>
> >
> > Hard to diagnose without the source code, but I'm thinking that your
> > __init__.py is probably trying to import from elsewhere in the
> > package? If so, try "from . import extract_video" instead.
> >
> Well, the traceback says that videotesting/__init__.py has:
>      from videotesting import extract_video
>
> so it is trying to import from itself during initialisation.

Yes, but what we can't tell is what the intention is. It could be
trying to import from its own package (in which case my suggestion
would be correct), or it could be trying to import from something
completely different (in which case the solution is to rename
something to avoid the conflict). Or it could be something else
entirely.

ChrisA


More information about the Python-list mailing list