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

2.9k views Asked by At

As the title says, I'm getting this error when trying to run this simple Python code:

import speedtest

r = speedtest.Speedtest()

Which results in

Traceback (most recent call last):
File "c:/Users/XXXX/YYYYYY/VSCode/Poli.py", line 3, in <module>
r = speedtest.Speedtest()
AttributeError: module 'speedtest' has no attribute 'Speedtest'

I've looked through all the posts I could find here in SE and on the web: getting an AttributeError: module 'speedtest' has no attribute 'Speedtest' python 'speedtest' has no attribute 'Speedtest' speedtest module in python speedtest-cli works in console, but not as script https://cloudstack.ninja/pratik-amonkar/how-can-i-fixed-error-of-speedtest-module/

All I could make out is that a speedtest.py exists somewhere in my project folder and it is messing things up, but I cannot find this particular file. I've reinstalled the package several times, changed my filename and tried other virtual environments as well. How can I avoid this error?

2

There are 2 answers

0
Merhai Akshay On

If you have used pip install speedtest probably thats whats causing the problem. Thats the wrong package installed. You have to uninstall the package speedtest using pip uninstall speedtest and instead install speedtest-cli using pip install speedtest-cli. The first line import speedtest is actually importing speedtest-cli.

*Note that you cant have both installed because then your script is actually trying to modify the file speedtest.py which was created when you did pip istall speedtest

0
RupamKarmakar On

check if you already installed the speedtest. if its installed then uninstall it pip uninstall speedtest and just install pip install speedtest-cli then try to run your script it will work.