Certbot no module named certbot

I'm running certbot on my development machine for testing.
I've had it install for some time and it normally works fine.

Today (after not using it from some weeks/months) it is broken.

When I run the certbot command it produces:

certbot
Traceback (most recent call last):
  File "/home/XXXX/.local/bin/certbot", line 5, in <module>
    from certbot.main import main
ModuleNotFoundError: No module named 'certbot'

If I run dwhich I find several copies of certbot on my path:

Found at: /home/XXX/.local/bin/certbot
Found at: /usr/bin/certbot
Found at: /bin/certbot

I'm not a python guy and I don't recall how I installed certbot except to say the 'apt' version didn't work (and isn't installed) as its on like version 0.4 and I have a feeling I had todo something with python profiles(?).

What is the recommended way to install certbot on ubuntu and how do I remove these bad versions?

OS:
Linux 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022

I can login to a root shell on my machine (yes or no, or I don't know): yes

Probably installed via pip install --user certbot.

Are probably the versions you got from apt.

Install it either via the snap or using a Python virtual environment.

apt remove certbot
pip uninstall certbot
rm -f ~USER/.local/bin/certbot
3 Likes

Thanks for the response.
After following your removal instructions:

apt remove certbot
pip uninstall certbot
rm -f ~USER/.local/bin/certbot

I was still left with

dwhich certbot
Found at: /usr/bin/certbot
Found at: /bin/certbot

And the error persisted.

Is it safe to just delete each of these certbot instances?

1 Like

I renamed the spurious certbot commands and then ran the snap install.

Certbot is now working.

So thanks for the help!

1 Like

Those are (were) probably symbolic links to other resources, which you can check using the ls -l command. You should be able to check this for the now-renamed certbot objects. If those are indeed symlinks to resources that are now removed due to your previous uninstall commands, you can also safely remove those now-defunct, renamed symlinks. If they're not symlinks, well, that's another story then.

3 Likes