python 'speedtest' has no attribute 'Speedtest'

Question:

I am trying to get the download and upload speed in python by using the "speedtest" module, but it gives me that error when I use the module:

AttributeError: module ‘speedtest’ has no attribute ‘Speedtest’.

and I was only declaring the variable,
that is my code :

import speedtest

speedtester = speedtest.Speedtest()

The module actually doesn’t have the functions for some reason.
Please tell me what is wrong with my code I was sure to import the module from the cmd and also the pycharm terminal and still got the same error.
Thanks in advance

Asked By: PXL Desiner

||

Answers:

I was getting the same error. Then I google the problem and eventually came here. Later I realised that I have named my python file speedtest.py. I renamed it to something else (which is not the name of any python module) and it works just fine now.

<–Screenshot–>

So make sure this case.

Answered By: hDmtP

I had the same issue. I was using PyCharm IDE.
The issue occurs when you install speedtest using pip install speedtest
In order to solve the above mentioned issue, you need to use the following command.

pip install speedtest-cli

But before doing this, uninstall the previous one by using pip uninstall speedtest
Screenshot to installation

Answered By: Hassan Shahzad

The issue got solved after moving the speedtest.py file to the same directory as my script and it worked just fine. So just make sure the file is in the same folder as your python script.

Answered By: PXL Desiner

Bumped into the issue and investigated the content of the module…
It appears what inside my venv folder I got a module folder "speedtest" with EMPTY init.py file and that is it…
Next to the folder was speedtest.py with actual code…
So deleting the empty folder/module helped me…

Answered By: DennisBY

If you installed "speedtest" and "speedtest-cli" libraries together then this issue will arise.

So first uninstall "speedtest" library using "pip uninstall speedtest" command.

Then try your code like :

"import speedtest
st = speedtest.Speedtest()
print(st.download()/1024)"

You will get output

Answered By: Anil Tank

You should uninstall before speedtest whit the command ‘pip uninstall speedtest’ . After that, this use this code to find download and upload, speeds and ping:

import speedtest

test = speedtest.Speedtest()

print("Loading server list...")
test.get_servers()
print("Choosing best server...")
best = test.get_best_server()

print(f"Found: {best['host']} located in {best['country']}")

print("Performing download test...")
download_result = test.download()
print("Performing upload test...")
upload_result = test.upload()
ping_result = test.results.ping

print(f"Download speed: {download_result / 1024 / 1024:.2f}Mbit/s")
print(f"Upload speed: {upload_result / 1024 / 1024:.2f}Mbit/s")
print(f"Ping: {ping_result}ms")
Answered By: Santiago Soñora

I was facing the same problem,but main problem might be you are installing speedtest library which is not suitable instead use pip install speedtest-cli but before that remember to delete the previous one using pip uninstall speedtest and check the spelling of get_servers which is in the plural form

i was also facing the same issue , what i have done is :
i have uninstall the speedtest and speedtest-cli

pip uninstall speedtest

pip uninstall speedtest-cli

then again install speedtest-cli

pip install speedtest-cli

Answered By: RAHUL CHATTERJEE

I got the same error. in pytho3 we cannot use the following code directly

import speedtest
wifi = speedtest.Speedtest()

Then it will give the error python ‘speedtest’ has no attribute ‘Speedtest’

Instead of that we can use following lines, it will support for Python3

from speedtest import Speedtest

internet = Speedtest()

download_speed = internet.download()
upload_speed = internet.upload() 

print("Download t:", download_speed)
print("Upload   t:", upload_speed)
Answered By: Gehan Fernando
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.