SMTPLIB

pip install smtplib Not Working

pip install smtplib fails — smtplib is in Python's standard library with no PyPI package. Use import smtplib. If that fails, a local file is shadowing it.

Updated Jul 1, 2026

The short answer

pip install smtplib fails ("No matching distribution found for smtplib") because smtplib is part of Python's standard library, not a PyPI package — there is nothing to install. Just remove the install command and import smtplib directly. If the import itself errors, you almost certainly have a local file shadowing a stdlib module (commonly email.py or smtplib.py); rename it and delete the stale .pyc.

Why is pip install smtplib not working?

Because there is nothing to install. smtplib is part of the Python standard library — it ships with every Python interpreter (CPython 2.3+ and all of Python 3). It is not published on PyPI, so pip has no distribution to download. That is exactly why you see:

ERROR: Could not find a version that satisfies the requirement smtplib
(from versions: none)
ERROR: No matching distribution found for smtplib

This is the same reason pip install json, pip install os, or pip install collections all fail — those are built-in modules, not packages.

How do I fix it?

You don't install it — you just import it. Delete the pip install smtplib line (and drop it from any requirements.txt), then use it directly:

import smtplib
with smtplib.SMTP("smtp.example.com", 587) as server:
server.starttls()
server.login("user@example.com", "app-password")
server.sendmail("user@example.com", "to@example.com", "Subject: Hi\n\nBody")

To confirm it's already available, run:

python -c "import smtplib; print(smtplib.__file__)"

That prints the path to smtplib.py inside your Python installation — proof it's present without pip.

What about the secure-smtplib package?

Some older answers tell you to run pip install secure-smtplib. Skip this on Python 3. secure-smtplib is a Python 2-only backport that added SMTP_SSL and TLS certificate validation to Python 2's smtplib. Python 3's standard smtplib already includes SMTP_SSL and starttls() natively, so the backport adds nothing and importing it does not give you a smtplib module. Installing it will not fix this error and only adds an unmaintained dependency (no release since 2015).

What if import smtplib itself fails?

If pip was never the problem and import smtplib raises ImportError/ModuleNotFoundError or an odd AttributeError, you almost certainly have a local file shadowing a standard-library module. The two usual culprits:

  • A file named smtplib.py in your project — Python imports your file instead of the stdlib one.
  • A file named email.py (or an email/ folder) — smtplib imports the stdlib email package internally, so shadowing it breaks smtplib too.

Fix it:

  1. Rename the offending file to something unique (e.g. my_email.py).
  2. Delete the stale compiled cache: remove the matching .pyc and any __pycache__/email.*.pyc / smtplib.*.pyc.
  3. Make sure you're not running from a directory containing such a file, and re-run import smtplib.

With Courier

If you reached this error while wiring up transactional or notification email, you can skip raw SMTP entirely. Courier sends email (plus SMS, push, and chat) through one API and routes across providers like SendGrid, Postmark, and Amazon SES — no SMTP socket handling, TLS negotiation, or per-provider auth to maintain.

FAQ

Common questions

Because smtplib is a Python standard-library module, not a PyPI package. It ships with every Python install, so pip has no distribution to download and returns 'No matching distribution found for smtplib.' Remove the install command and just use import smtplib.

One API, every provider

Stop debugging raw provider errors

Courier connects to your email, SMS, and push providers, handles retries and failover, and surfaces delivery errors in plain language.

Last reviewed Jul 1, 2026. Courier is not affiliated with third-party providers; error behavior may vary by implementation.