Using pip behind a proxy with CNTLM
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In corporate networks, pip often cannot reach package indexes directly because outbound traffic must pass through an authenticated proxy. CNTLM solves that by running a small local proxy that speaks NTLM to the corporate proxy, letting tools like pip talk to localhost instead of handling enterprise authentication themselves.
How the Setup Works
The flow is usually:
pip only needs a normal HTTP or HTTPS proxy URL. CNTLM handles the hard part of authenticating with the upstream enterprise proxy.
Step 1: Configure CNTLM
A minimal cntlm.conf or cntlm.ini usually contains:
Instead of storing a plain-text password, CNTLM can generate password hashes:
That command prompts for the password and prints hash values you can place in the config file.
After configuration, start CNTLM and make sure it listens on the chosen local port, often 3128.
Step 2: Point pip at CNTLM
The quickest test is to pass the proxy on the command line:
If that works, the CNTLM side is healthy and the remaining job is making the proxy setting persistent.
Step 3: Persist the Proxy Setting
You can configure pip with environment variables:
Or put the setting in pip configuration:
You can inspect your current pip configuration with:
This is often cleaner than passing --proxy on every install command.
Example End-to-End Check
Once CNTLM is running, verify the connection in small steps.
First, check that CNTLM is reachable locally:
Then try pip:
If curl fails, the issue is probably CNTLM or the corporate proxy. If curl works but pip fails, inspect pip configuration, certificates, or Python environment differences.
HTTPS, Certificates, and Corporate Inspection
Some corporate proxies intercept TLS traffic and re-sign certificates. In those environments, pip may fail with certificate errors even after the proxy is correct.
Typical fixes include:
- install the corporate root certificate into the system trust store
- point
pipto a certificate bundle withcert = /path/to/cert.pem - avoid using
trusted-hostas a casual shortcut unless policy and risk are understood
Proxy problems and certificate problems often appear together, but they are different layers.
A Useful pip Config Example
If your team uses an internal mirror plus CNTLM, a more complete config might look like:
You can set these values with commands as well:
Troubleshooting Sequence
When the setup does not work, debug in this order:
- confirm CNTLM is running
- confirm CNTLM can authenticate to the upstream proxy
- test the local proxy with
curl - test
pip --proxy ... - inspect certificate and
pip configissues
This order matters because many developers change pip settings repeatedly when the real problem is that CNTLM never connected upstream.
Common Pitfalls
- Pointing
pipdirectly at the corporate NTLM proxy instead of the local CNTLM listener. - Forgetting to start the CNTLM service before running installs.
- Mixing shell environment variables with
pipconfig and then not knowing which proxy is actually in effect. - Treating TLS certificate failures as proxy failures.
- Leaving a stale proxy setting in
pipconfig after moving to a different network.
Summary
- CNTLM acts as a local NTLM-aware proxy that
pipcan use like a normal proxy. - Configure CNTLM first, then point
pipathttp://127.0.0.1:3128or your chosen local port. - Use
--proxyfor quick testing andpip configor environment variables for persistent setup. - If installs still fail, separate proxy connectivity issues from certificate issues.
- Debug from CNTLM outward rather than guessing inside
pip.

