在 Jupyter 中下载文件:Windows 上的 wget?
Downloading files in Jupyter: wget on Windows?
我正在尝试从 url 下载文件。
我发现 wget
命令可以做到这一点。因为我使用 Jupyter,所以我不想使用 pip
,但是 conda install conda wget
没有用,因为默认存储库中没有 Windows wget
。因此我做了 conda install menpo wget
并成功安装了 wget
。但是我仍然无法在 JupyterLab 中导入 wget
:
ModuleNotFoundError: No module named 'wget'
- 是否还有其他导入步骤
wget
?
- 有没有更好的在 Jupyter 中下载文件的方法?
正如 Trenton_M 指出的那样,有一个 urllib
库可以替代 wget
:
import urllib.request
url = 'https://address'
filename = 'myfile.txt'
urllib.request.urlretrieve(url, filename)
在 Google-Collab 中,此代码运行良好:
!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
但不在本地 Windows 10. 在我的 Jupyter Notebook 单元格中,此代码:
# 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
保存文件和returns:
Saved under sample_f.mp3
Saved under sample_m.mp3
或者我尝试了另一种方法:我从 here 下载 wget.exe for Windows 并将其移动到 PATH 目录。然后代码也可以工作:
!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
我正在尝试从 url 下载文件。
我发现 wget
命令可以做到这一点。因为我使用 Jupyter,所以我不想使用 pip
,但是 conda install conda wget
没有用,因为默认存储库中没有 Windows wget
。因此我做了 conda install menpo wget
并成功安装了 wget
。但是我仍然无法在 JupyterLab 中导入 wget
:
ModuleNotFoundError: No module named 'wget'
- 是否还有其他导入步骤
wget
? - 有没有更好的在 Jupyter 中下载文件的方法?
正如 Trenton_M 指出的那样,有一个 urllib
库可以替代 wget
:
import urllib.request
url = 'https://address'
filename = 'myfile.txt'
urllib.request.urlretrieve(url, filename)
在 Google-Collab 中,此代码运行良好:
!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
但不在本地 Windows 10. 在我的 Jupyter Notebook 单元格中,此代码:
# 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
保存文件和returns:
Saved under sample_f.mp3
Saved under sample_m.mp3
或者我尝试了另一种方法:我从 here 下载 wget.exe for Windows 并将其移动到 PATH 目录。然后代码也可以工作:
!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