首页 > 解决方案 > 在 Windows CMD 中使用来自 python 的 wget 或 curl

问题描述

我对 Python 很陌生。我已经Python 3.7.3在我的 Windows 上安装并想使用 CMD 来运行.py文件。

命令就像py xxx.py它实际上是从服务器下载一些文件。

当它询问“是否可以下载”时,我点击“是”。

然后出现了一条消息。

该脚本需要在系统上使用 curl 或 wget,请在运行脚本之前先安装它们!

然后程序将退出。

但是当我尝试运行时pip install wget出现此消息:

已满足要求:c:\users\qin_l\appdata\local\programs\python\python37-32\lib\site-packages (3.2) 中的 wget

当我输入时py -m wget xxx.file,我可以下载文件(不是我想要的)

我猜无法通过窗户的部分是

# Check if curl or wget commands exsit on your computer
if sys.version_info >= (3,0):
status_curl, result = subprocess.getstatusoutput('which curl')
status_wget, result = subprocess.getstatusoutput('which wget')
else:
status_curl, result = commands.getstatusoutput("which curl")
status_wget, result = commands.getstatusoutput("which wget")

并且相应地

if status_curl == 0:
    cmd='curl -g "'+cmd+'" -o '+ ncout
  elif status_wget == 0:
    cmd='wget "'+cmd+'" -O '+ ncout
  else:
    sys.exit('\nThe script will need curl or wget on the system, please install them first before running the script !\nProgram will exit now !\n')

它似乎wget可以在 Python 中工作,但不能在 py 文件中工作。我在这里超级困惑。我必须安装 Linux 并在 Ubuntu 中运行命令吗?

标签: pythoncurlwget

解决方案


您拥有的脚本期望wgetcurl将作为命令行工具安装,即。您可以从 CMD 提示符运行它们。

令人困惑的是,还有一个名为 wget 的 python 包,它是与 一起安装的pip install wget,但它完全不同..

要安装命令行wget,首先使用 Powershell安装Scoopwget ,然后使用scoop install wget.


推荐阅读