yt-dlp: "module yt_dlp.dependencies.Cryptodome has no attribute Cipher" error after upgrading from 2023.01.06 to 2023.02.17 via pip

DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

  • I understand that I will be blocked if I intentionally remove or skip any mandatory* field

Checklist

  • I’m reporting a bug unrelated to a specific site
  • I’ve verified that I’m running yt-dlp version 2023.02.17 (update instructions) or later (specify commit)
  • I’ve checked that all provided URLs are playable in a browser with the same IP and same login details
  • I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
  • I’ve searched known issues and the bugtracker for similar issues including closed ones. DO NOT post duplicates
  • I’ve read the guidelines for opening an issue

Provide a description that is worded well enough to be understood

I’m having a dependency issue on the newest version of yt_dlp (see Verbose Output). I tried purging the pip3 cache and uninstalling yt_dlp and it’s dependencies then reinstalling:

python3 -m pip install yt_dlp Collecting yt_dlp Downloading yt_dlp-2023.2.17-py2.py3-none-any.whl (2.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.9/2.9 MB 10.2 MB/s eta 0:00:00 Collecting pycryptodomex Downloading pycryptodomex-3.17-cp35-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 32.2 MB/s eta 0:00:00 Collecting websockets Downloading websockets-10.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (106 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 106.7/106.7 kB 11.7 MB/s eta 0:00:00 Collecting brotli Downloading Brotli-1.0.9-cp37-cp37m-manylinux1_x86_64.whl (357 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 357.2/357.2 kB 24.9 MB/s eta 0:00:00 Collecting mutagen Downloading mutagen-1.46.0-py3-none-any.whl (193 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 193.6/193.6 kB 19.2 MB/s eta 0:00:00 Collecting certifi Downloading certifi-2022.12.7-py3-none-any.whl (155 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 155.3/155.3 kB 17.2 MB/s eta 0:00:00 Installing collected packages: brotli, websockets, pycryptodomex, mutagen, certifi, yt_dlp Successfully installed brotli-1.0.9 certifi-2022.12.7 mutagen-1.46.0 pycryptodomex-3.17 websockets-10.4 yt_dlp-2023.2.17

Error remains. Reverting to yt_dlp 2023.01.06 makes error go away.

Provide verbose output that clearly demonstrates the problem

  • Run your yt-dlp command with -vU flag added (yt-dlp -vU <your command line>)
  • Copy the WHOLE output (starting with [debug] Command-line config) and insert it below

Complete Verbose Output

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/yt_dlp/compat/compat_utils.py", line 36, in __getattribute__
    ret = super().__getattribute__(attr)
  File "/usr/local/lib/python3.7/site-packages/yt_dlp/compat/compat_utils.py", line 56, in __getattr__
    raise AttributeError(f'module {parent.__name__} has no attribute {attr}')
AttributeError: module yt_dlp.dependencies.Cryptodome has no attribute Cipher

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/yt-dlp", line 5, in <module>
    from yt_dlp import main
  File "/usr/local/lib/python3.7/site-packages/yt_dlp/__init__.py", line 18, in <module>
    from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS
  File "/usr/local/lib/python3.7/site-packages/yt_dlp/cookies.py", line 18, in <module>
    from .aes import (
  File "/usr/local/lib/python3.7/site-packages/yt_dlp/aes.py", line 5, in <module>
    from .dependencies import Cryptodome
  File "/usr/local/lib/python3.7/site-packages/yt_dlp/dependencies/__init__.py", line 76, in <module>
    Cryptodome_AES = Cryptodome.Cipher.AES if Cryptodome else None
  File "/usr/local/lib/python3.7/site-packages/yt_dlp/compat/compat_utils.py", line 43, in __getattribute__
    ret = getter(attr)
  File "/usr/local/lib/python3.7/site-packages/yt_dlp/compat/compat_utils.py", line 56, in __getattr__
    raise AttributeError(f'module {parent.__name__} has no attribute {attr}')
AttributeError: module yt_dlp.dependencies.Cryptodome has no attribute Cipher

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I am also getting this issue, but only when using pyinstaller. Installing cffi does not do anything.

My issue is resolved as well now. As I was starting to gather the information that @pukkandan asked for, it looks like the following two commands completely fixed my problem (use pip to downgrade yt-dlp to 2023.1.6, and then upgrade it back to 2023.02.17): pip install yt-dlp==2023.1.6 pip install yt-dlp==2023.02.17

This seemed to properly install yt-dlp together will all needed dependencies, including pycryptodomex and mutagen.

The way I was using yt-dlp previously was not through pip, but from the release binaries. And then I was running yt-dlp -U to keep upgrading it to the latest version. I guess at some point something went wrong and then this issue showed up. But now, reinstalling yt-dlp through pip has resolved the issue.

In the end I did not have to resort to using @pukkandan’s diff solution workaround.

"Me too"s without additional details isn’t helping anyone. I have yet to be able to reproduce the issue.

If you are having the issue, run the following and post their outputs:

  • yt-dlp -v on both the new and old versions (use pip install yt-dlp==2023.1.6 to install old version)
  • If on PIP (change py to python/python3 if needed):
    • py -c "from Cryptodome.Cipher import AES; print(AES)"
    • py -c "from Crypto.Cipher import AES; print(AES)"
    • pip install cffi
    • Repeat the first 2
    • (pip freeze may also help)
  • If compiled yourself (pyinstaller etc)
    • Everything from PIP section
    • Post exact steps of how you compiled it

My guess is that cryptodome install is somehow broken in your systems and previous versions of yt-dlp were silently ignoring the error[^1]. If I am right, it’s an easy fix to make yt-dlp ignore the error again. But first I need to be sure

If you can, also test if this works around the problem

diff --git a/yt_dlp/dependencies/Cryptodome.py b/yt_dlp/dependencies/Cryptodome.py
index 7e339602c..34c644be8 100644
--- a/yt_dlp/dependencies/Cryptodome.py
+++ b/yt_dlp/dependencies/Cryptodome.py
@@ -5,9 +5,11 @@

 try:
     import Cryptodome as _parent
+    from Cryptodome.Cipher import AES
 except ImportError:
     try:
         import Crypto as _parent
+        from Crypto.Cipher import AES
     except (ImportError, SyntaxError):  # Old Crypto gives SyntaxError in newer Python
         _parent = types.ModuleType('no_Cryptodome')
         __bool__ = lambda: False

[^1]: There was a try: except ImportError around entire import call

Does pip install cffi fix the issue?

I tried downgrading and then upgrading, doing the fix here. this runs fine locally, but when i deploy it to AWS lambda now it fails with the following error. Any suggestions?

[ERROR] OSError: Cannot load native module 'Cryptodome.Cipher._raw_ecb': Not found '_raw_ecb.cpython-39-x86_64-linux-gnu.so',

data:

(env) ➜ lambdas git:(master) ✗ yt-dlp -v [debug] Command-line config: [‘-v’] [debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8 [debug] yt-dlp version 2023.02.17 [a0a7c01] (pip) [debug] Python 3.8.9 (CPython x86_64 64bit) - macOS-12.1-x86_64-i386-64bit (LibreSSL 2.8.3) [debug] exe versions: ffmpeg 5.1.2 (setts), ffprobe 5.1.2 [debug] Optional libraries: Cryptodome-3.17, brotli-1.0.9, certifi-2022.12.07, mutagen-1.46.0, sqlite3-2.6.0, websockets-11.0.1 [debug] Proxy map: {} [debug] Loaded 1782 extractors

Usage: yt-dlp [OPTIONS] URL [URL…]

yt-dlp: error: You must provide at least one URL. Type yt-dlp --help to see a list of all options.


(env) ➜ lambdas git:(master) ✗ python3 -c “from Cryptodome.Cipher import AES; print(AES)” <module ‘Cryptodome.Cipher.AES’ from ‘/Users/pietrosette/Documents/autoclip/lambdas/env/lib/python3.8/site-packages/Cryptodome/Cipher/AES.py’>

(env) ➜ lambdas git:(master) ✗ python3 -c “from Crypto.Cipher import AES; print(AES)” Traceback (most recent call last): File “<string>”, line 1, in <module> ModuleNotFoundError: No module named ‘Crypto’