Fixing the pydivert ModuleNotFoundError in sshuttle on Windows with pipx
This guide explains why sshuttle fails to import pydivert on Windows when installed via pipx, details pipx’s isolation mechanism, and provides a step‑by‑step solution using pipx inject and driver installation to get sshuttle running correctly.
When installing sshuttle with pipx on Windows, the program crashes with ModuleNotFoundError: No module named 'pydivert' even though pydivert is installed globally. The error log shows that sshuttle tries to import pydivert, which is required for the windivert method that captures and modifies network packets.
Why a global pydivert install doesn’t help
pipxcreates an isolated virtual environment for each installed application. When sshuttle is installed via pipx, it runs inside its own environment that cannot see packages installed in the global Python environment. Therefore, the pydivert module installed globally is invisible to the sshuttle virtual environment, causing the import error.
Solution: Inject pydivert into the sshuttle environment
Use pipx inject to add pydivert directly to the virtual environment that sshuttle uses.
Locate the sshuttle virtual environment (optional) : The environment is typically at C:\Users\heish\pipx\venvs\sshuttle. Knowing the path helps understand where the injection will occur.
Run the injection command in a PowerShell or CMD window: pipx inject sshuttle pydivert This tells pipx to install pydivert into the sshuttle environment.
Install the WinDivert driver (if not already present) : pydivert is a Python wrapper for the WinDivert driver. If the driver is missing, download it from the official WinDivert GitHub repository or the PyPI page and place the driver DLL in C:\Windows\System32 or C:\Windows\SysWOW64. Running the pydivert installer as administrator may also handle this automatically.
Rerun sshuttle with your usual command, e.g.: sshuttle --dns -Nr [email protected] 172.31.0.0/16 After the injection, sshuttle should successfully import pydivert and start.
Practical tips and further considerations
Prefer pipx inject over global installation when a pipx -managed app lacks a dependency.
Consult the pipx documentation ( pipx --help) for all available commands and options.
Understand virtual‑environment isolation: tools like venv, conda, and pipx keep dependencies separate to avoid conflicts.
Be aware of Windows‑specific requirements: libraries that rely on low‑level drivers (e.g., pydivert) may need administrator privileges or manual driver placement.
Check the official sshuttle documentation or GitHub issues for platform‑specific guidance.
Conclusion
pipxprovides convenient isolation for Python CLI tools, but understanding its mechanics is essential for troubleshooting. By using pipx inject to add missing dependencies like pydivert directly into the target application's environment, you can resolve import errors and get sshuttle working on Windows.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development & AI Practice
DevSecOps engineer sharing experiences and insights on AI, Web3, and Claude code development. Aims to help solve technical challenges, improve development efficiency, and grow through community interaction. Feel free to comment and discuss.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
