简体   繁体   English

在 Python3 脚本中使用 speedtest-cli 来测量互联网速度 - 收到错误消息“No module named speedtest”

[英]Using speedtest-cli within a Python3 script to measure internet speed - getting error message 'No module named speedtest'

My vacation home loses the internet connection from time to time which means I cannot access that locations' home network remotely.我的度假屋不时失去互联网连接,这意味着我无法远程访问该地点的家庭网络。 I am using a wireless Bell service as my ISP.我使用无线贝尔服务作为我的 ISP。 When I am at the vacation home, I have a program within my home automation system to reboot the Bell PoE device and the Modem.当我在度假屋时,我的家庭自动化系统中有一个程序可以重新启动 Bell PoE 设备和调制解调器。 This generally always resets the network.这通常总是重置网络。

I am trying to use the Github project Python script speedtest-cli to measure the download speed at my vacation home.我正在尝试使用 Github 项目 Python 脚本speedtest-cli来测量我度假屋的下载速度。 I am trying to write my own Python script, on a Raspberry Pi (Buster), to periodically measure the download speed of the internet.我正在尝试在 Raspberry Pi (Buster) 上编写自己的 Python 脚本,以定期测量互联网的下载速度。 My plan is to then send a variable, with the speed, to my home automation system that will trigger a reset of the internet if the speed is too low.我的计划是将一个带有速度的变量发送到我的家庭自动化系统,如果速度太低,它将触发互联网重置。

I downloaded the latest script from Github using the code我使用代码从 Github 下载了最新的脚本

wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py

Then I made the file executable with然后我使文件可执行

chmod +x speedtest-cli

When I run the command speedtest-cli , at the Raspeberry Pi's command line, the script works as expected and I see the download speed.当我在 Raspeberry Pi 的命令行中运行命令speedtest-cli 时,脚本按预期工作,我看到了下载速度。

However, when I try to incorporate the code into a python script I get the error 'No module named 'speedtest'但是,当我尝试将代码合并到 python 脚本中时,我收到错误“No module named 'speedtest'

The simple code that yields this message is产生此消息的简单代码是

import speedtest

I am running the simple script above from the /home/pi/ directory and the executable 'speedtest-cli' is also in that directory我正在 /home/pi/ 目录中运行上面的简单脚本,并且可执行文件“speedtest-cli”也在该目录中

(I know that there are numerous comments that this 'speedtest' project isn't providing accurate results, however from my testing it has been consistently yielding results that are sufficient for my purposes) (我知道有很多评论说这个“速度测试”项目没有提供准确的结果,但是从我的测试来看,它一直产生足以满足我的目的的结果)

Any thought on why this isn't working?关于为什么这不起作用的任何想法?

For using speedtest-cli via a python script, would require you to install speedtest-cli on your local machine.要通过 python 脚本使用speedtest-cli ,需要您在本地机器上安装 speedtest-cli。

git clone https://github.com/sivel/speedtest-cli.git
cd speedtest-cli
python setup.py install

After that you can use import speedtest之后,您可以使用import speedtest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 speedtest-cli 在控制台中工作,但不能作为脚本使用 - speedtest-cli works in console, but not as script 有没有办法在速度测试期间使用 Python 的 speedtest-cli 库实时绘制实时下载/上传速度? - Is there a way to graph the real-time download/upload speed real time during a speed test using the speedtest-cli library for Python? 不同界面上的 Speedtest-cli - Speedtest-cli on a different interface 我如何在python脚本中使用speedtest-cli或任何替代方法而不是命令行? - How do i use speedtest-cli or any alternative in python script instead of command line? 获取 AttributeError: 模块“speedtest”没有属性“Speedtest” - getting an AttributeError: module 'speedtest' has no attribute 'Speedtest' python 中的速度测试模块 - speedtest module in python 速度测试 python 脚本 - Speedtest python script 创建一个python函数以在终端中运行speedtest-cli / ping并将结果输出到日志文件 - Create a python function to run speedtest-cli/ping in terminal and output result to a log file 使用 python kivy 进行速度测试 - Speedtest using python kivy 更改 speedtest.py 和 speedtest-cli 的 output 以将 IP 地址包含在 output.Z628Z19675FFE88FEF3F 文件中 - Changing output of speedtest.py and speedtest-cli to include IP address in output .csv file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM