如何在Jupyter Notebook中使用wget命令?VS Code环境运行遇阻
在VS Code的Jupyter Notebook中使用wget的解决方法
Colab能直接用wget是因为它的运行环境是Linux虚拟机,默认自带这个工具,但本地VS Code的Jupyter用的是你电脑本身的系统环境,Windows默认没有wget,Linux/macOS如果没装也会报错,给你几个解决办法:
方法一:用Python内置库替代(跨平台通用)
不用依赖系统的wget,直接写Python代码下载,兼容性拉满:
import requests # 替换成你要下载的文件链接 target_url = "https://example.com/your-file.zip" # 替换成你想保存的文件名 save_name = "downloaded-file.zip" response = requests.get(target_url) with open(save_name, "wb") as file: file.write(response.content)
方法二:给系统安装wget
Windows环境
- 用Chocolatey包管理器安装:打开管理员PowerShell,执行
choco install wget(没装Chocolatey的话先装它) - 或者直接下载wget.exe,放到
C:\Windows\System32这类系统PATH目录里,之后在Jupyter单元格里就能用!wget 你的链接了
Linux/macOS环境
- Ubuntu/Debian:打开终端执行
sudo apt install wget - macOS:用Homebrew执行
brew install wget
安装完成后,在Jupyter单元格里输入!wget 你的链接就能正常运行
内容的提问来源于stack exchange,提问作者Candy
相关产品推荐
相关产品推荐

