1

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?

LFSS
  • 115
  • 1
  • 7
  • 4
    `import speedtest; print(speedtest.__file__)` – user2357112 Apr 14 '21 at 21:55
  • Right -- you need to look at what you *do* have as `speedtest`. @user2357112supportsMonica gave you a "quick strike" to check. If this interests you, look up the various package inspection methods available in Python. – Prune Apr 14 '21 at 21:58
  • Just a guess - is it maybe `speedtest.SpeedTest` instead of `speedtest.Speedtest` ? – TheEagle Apr 14 '21 at 22:12
  • As the first comment suggested, I ran that code and it gave me this: C:\Users\XXXX\YYYY\VSCode\speed\lib\site-packages\speedtest\__init__.py. Which is a file that only contains the following lines: # -*- coding: utf-8 -*- __version__ = "0.0.1" I have no idea what to do now. – LFSS Apr 16 '21 at 19:31

2 Answers2

3

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

Merhai Akshay
  • 55
  • 1
  • 5
0

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.