12

I am trying to download files from a url.

I found wget command to be able to do that. Since I use Jupyter, I did not want to use pip, however conda install conda wget didn't work as there is no Windows wget in the default repository. Thus I did conda install menpo wget which successfully installed wget. However I still cannot import wget in JupyterLab: ModuleNotFoundError: No module named 'wget'

  1. Are there any other steps to import wget?
  2. Is there a better way to download files in Jupyter?
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
stinglikeabeer
  • 455
  • 1
  • 3
  • 11

2 Answers2

19

As Trenton_M pointed out, there is a urllib library that can do it instead of wget:

import urllib.request
url = 'https://address'
filename = 'myfile.txt'
urllib.request.urlretrieve(url, filename)
jonchar
  • 6,183
  • 1
  • 14
  • 19
stinglikeabeer
  • 455
  • 1
  • 3
  • 11
12

In Google-Collab this code works well:

!wget https://audio-previews.elements.envatousercontent.com/files/6319559/preview.mp3 -O sample_f.mp3
!wget https://audio-previews.elements.envatousercontent.com/files/256324900/preview.mp3 -O sample_m.mp3

But not locally on Windows 10. In my Jupyter Notebook cell this code:

# pip install wget
!python -m wget https://audio-previews.elements.envatousercontent.com/files/6319559/preview.mp3 -o sample_f.mp3
!python -m wget https://audio-previews.elements.envatousercontent.com/files/256324900/preview.mp3 -o sample_m.mp3

Saves files and returns:

Saved under sample_f.mp3
Saved under sample_m.mp3

OR I tried another way: I downloaded wget.exe for Windows from here and moved it to PATH-directory. Then code works too:

!wget https://audio-previews.elements.envatousercontent.com/files/6319559/preview.mp3 -O sample_f.mp3
!wget https://audio-previews.elements.envatousercontent.com/files/256324900/preview.mp3 -O sample_m.mp3
Jackssn
  • 1,346
  • 1
  • 14
  • 16