python - 在 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 中运行命令吗?
解决方案
您拥有的脚本期望wget
或curl
将作为命令行工具安装,即。您可以从 CMD 提示符运行它们。
令人困惑的是,还有一个名为 wget 的 python 包,它是与 一起安装的pip install wget
,但它完全不同..
要安装命令行wget
,首先使用 Powershell安装Scoopwget
,然后使用scoop install wget
.
推荐阅读
- java - 使用范围报告将 java 机器人屏幕截图保存到 testng 侦听器中
- r - 使用 R 中最接近的较低值合并两个数据帧
- python-3.x - 使用字符串组合转义反斜杠
- vim - 如何从vim中的行中拆分前2列?
- r - 如何从 R Markdown 文档生成 PDF 标题页
- python - 对 arr[-1] 的困惑以及反向的作用
- node.js - 如何解决“节点不被识别为内部或外部命令等”
- node.js - Heroku 错误节点,mongo,react(错误 R10(启动超时)-> Web 进程未能在启动后 60 秒内绑定到 $PORT)
- datastage - 如何捕获文件中的最后一条记录
- reactjs - 从反应页面路由到角度页面