'python 'speedtest' has no attribute 'Speedtest'
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
Solution 1:[1]
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.
Solution 2:[2]
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
Solution 3:[3]
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.
So make sure this case.
Solution 4:[4]
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
Solution 5:[5]
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...
Solution 6:[6]
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")
Solution 7:[7]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | PXL Desiner |
Solution 2 | pyeR_biz |
Solution 3 | hDmtP |
Solution 4 | Anil Tank |
Solution 5 | DennisBY |
Solution 6 | |
Solution 7 | siddiqui Adaab husain |