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

ImportError: cannot import name 'FFMPEG_CODECS' from partially initialized module 'minim' (most likely due to a circular import) #10

Closed
s-lopez opened this issue Mar 8, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@s-lopez
Copy link

s-lopez commented Mar 8, 2024

Hello!

I was about to give minim a try, since it looks super interesting, and I'm getting this circular import error as soon as I try to import minim:
ImportError: cannot import name 'FFMPEG_CODECS' from partially initialized module 'minim' (most likely due to a circular import)

I followed the instructions to install the dependencies and the project in editable mode with virtualenv. I'm using Python 3.11 and macOS 14.3.1.

The error appears as soon as I import minim (python -c "import minim").

I've looked into it and indeed, src/minim/__init__.py contains from . import audio, itunes, qobuz, spotify, tidal, utility # noqa: E402 in line 42, and src/minim/audio.py has the following in line 22: from . import utility, FOUND_FFMPEG, FFMPEG_CODECS. FOUND_FFMPEG is defined in __init__.py.

@bbye98
Copy link
Owner

bbye98 commented Mar 8, 2024

Hi! Thanks for opening an issue.

I was unable to reproduce this issue by cloning the GitHub repository as it is now and installing it in a new Conda environment. Can you give me the exact steps you used to initialize your virtualenv?

Or better question: do you have FFmpeg installed? If not, I think it might be because I included FFMPEG_CODECS in __all__ in __init__.py, even if it was never defined if you don't have FFmpeg. It may also be possible that shutil is not able to find your installation of FFmpeg: pyinstaller/pyinstaller#5925.

I'm going to try my best to figure out the root cause, but I only have access to Windows and Ubuntu currently, not macOS. Hopefully this is an OS-independent issue!

Thanks!

@bbye98 bbye98 self-assigned this Mar 8, 2024
@bbye98 bbye98 added bug Something isn't working help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Mar 8, 2024
@s-lopez
Copy link
Author

s-lopez commented Mar 8, 2024

Thanks to you for taking a look at this so quickly and for publishing your library!

Ok, good news: Installing FFmpeg with homebrew and installing the full dependencies from requirements.txt does the trick. I can now successfully import the package. Thanks!

Now the details:

  • Installing FFmpeg and "only" pip install -e . still results in ModuleNotFoundError: No module named 'cryptography'. Full trace:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "~/python/minim/src/minim/__init__.py", line 42, in <module>
    from . import audio, itunes, qobuz, spotify, tidal, utility # noqa: E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/python/minim/src/minim/tidal.py", line 27, in <module>
    from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes

So I'm guessing the issue is indeed OS-independent, except for the conda part, of course 😄

@bbye98
Copy link
Owner

bbye98 commented Mar 8, 2024

Thanks for the detailed response! I will address the cryptography issue when I get home and push a fix to GitHub.

@bbye98 bbye98 closed this as completed in 3a61940 Mar 9, 2024
@s-lopez
Copy link
Author

s-lopez commented Mar 11, 2024

@bbye98 I think other users might still see the circular import error if they don't have FFmpeg in their system.

@bbye98
Copy link
Owner

bbye98 commented Mar 11, 2024

Whoops! Forgot to update audio.py. Hopefully this push fixes the issue.

@bbye98 bbye98 reopened this Mar 11, 2024
@bbye98 bbye98 closed this as completed in 01280e4 Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants