pythonpython-3.xgoogle-colaboratorylibtorrent

libtorrent module not found


I use this code to download from torrent to drive using google colab

1   !apt install python3-libtorrent
2
3   import libtorrent as lt
4 
5   ses = lt.session()
6   ses.listen_on(6881, 6891)
7   downloads = []

It runs out an error in line 3 saying:

ModuleNotFoundError: No module named 'libtorrent'  

The complete output is

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-libtorrent is already the newest version (1.1.5-1build1).
0 upgraded, 0 newly installed, 0 to remove and 13 not upgraded.
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-1098f0f9d9d1> in <module>()
      1 get_ipython().system('apt install python3-libtorrent')
      2 
----> 3 import libtorrent as lt
      4 
      5 ses = lt.session()

ModuleNotFoundError: No module named 'libtorrent'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

I tried using pip instead of apt and it didn't work. There was another error saying:

Could not find a version that satisfies the requirement python3-libtorrent (from versions: none) No matching distribution found for python3-libtorrent

The output was

ERROR: Could not find a version that satisfies the requirement python3-libtorrent (from versions: none)
ERROR: No matching distribution found for python3-libtorrent
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-b9ec203eb952> in <module>()
      1 get_ipython().system('pip install python3-libtorrent')
      2 
----> 3 import libtorrent as lt
      4 
      5 ses = lt.session()

ModuleNotFoundError: No module named 'libtorrent'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Solution

  • Kindly follow the below given YouTube link. This would be helpful to you.

    https://youtu.be/kFG2YHVGZLs

    In short, just add the following two lines before "!apt install python3-libtorrent"

    !python -m pip install --upgrade pip setuptools wheel

    !python -m pip install lbry-libtorrent