简体   繁体   English

speedtest-cli 在控制台中工作,但不能作为脚本使用

[英]speedtest-cli works in console, but not as script

I am trying to use the speedtest-cli api.我正在尝试使用 speedtest-cli api。 Copied part of the code from official wiki (and removed unused stuff):从官方维基复制部分代码(并删除了未使用的东西):

import speedtest
s = speedtest.Speedtest()
s.get_best_server()
s.download()

In python console I get everything ok:在 python 控制台中,我一切正常:

>>> import speedtest
>>> s = speedtest.Speedtest()
>>> s.get_best_server()
{HIDDEN}
>>> s.download()
37257579.09084724

But when I create .py file and run it I get:但是当我创建 .py 文件并运行它时,我得到:

AttributeError: module 'speedtest' has no attribute 'SpeedTest'

Thanks谢谢

As mentioned in the comments, you have a file with the same name and it is conflicting with the import.正如评论中提到的,您有一个同名的文件,它与导入冲突。 Since you have moved the file, restarting the console should work.由于您已经移动了文件,重新启动控制台应该可以工作。

The code below will also extract the results into a dictionary and make it possible to access the results.下面的代码还将结果提取到字典中,并可以访问结果。

import speedtest
s = speedtest.Speedtest()
s.get_best_server()
s.download()
s.upload()
res = s.results.dict()
print(res["download"], res["upload"], res["ping"])

Try checking speedtest is imported properly尝试检查 speedtest 是否正确导入

import speedtest
print(dir(speedtest))

it should display properties of speedtest它应该显示速度测试的属性

I faced the same issue because I had installed both speedtest and speedtest-cli.我遇到了同样的问题,因为我同时安装了 speedtest 和 speedtest-cli。 Using pip uninstall speedtest worked for me.使用pip uninstall speedtest对我pip uninstall speedtest

暂无
暂无

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

相关问题 不同界面上的 Speedtest-cli - Speedtest-cli on a different interface 在 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' 我如何在python脚本中使用speedtest-cli或任何替代方法而不是命令行? - How do i use speedtest-cli or any alternative in python script instead of command line? 更改 speedtest.py 和 speedtest-cli 的 output 以将 IP 地址包含在 output.Z628Z19675FFE88FEF3F 文件中 - Changing output of speedtest.py and speedtest-cli to include IP address in output .csv file 创建一个python函数以在终端中运行speedtest-cli / ping并将结果输出到日志文件 - Create a python function to run speedtest-cli/ping in terminal and output result to a log file 有没有办法在速度测试期间使用 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? 速度测试 python 脚本 - Speedtest python script 相对导入适用于CLI但不适用于脚本 - Relative import works on CLI but not in script python chef在控制台中工作而不是脚本 - python chef works in console not in script Python SSHTunnel w / Paramiko - CLI可以工作,但不能在脚本中工作 - Python SSHTunnel w/ Paramiko - CLI works, but not in script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM