Search code examples
pythonpython-3.xlinuxpwntoolspipx

ModuleNotFoundError: No module named 'pwn' even though I installed pwntools with pipx, and already set PYTHONPATH


I'm working on arch linux.

I need the python module 'pwntools'. First I did this:

pipx install pwntools

Then a warning:

Note: '/home/woc/.local/bin' is not on your PATH environment variable. These apps will not be globally accessible until your PATH is updated. Run pipx ensurepath to automatically add it, or manually modify your PATH in your shell's config file (e.g. ~/.bashrc).

What I tried: Then I add ~/.local/bin to both my PATH and PYTHONPATH. And I checked it, seeming no problem.

print (sys.path)

['', '/home/woc/.local/bin', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/usr/lib/python3.12/site-packages']

And there are many modules in ~/.local/bin, including one named 'pwn'

What I expected: import the modules in ~/.local/bin

However, when I import pwn (a module in that directory) in python code, I was told ModuleNotFoundError: No module named 'pwn'

Why???


Solution

  • The whole point of pipx is to install Python applications (not libraries) such that their dependencies are isolated from the rest of the system:

    pipx is made specifically for application installation, as it adds isolation yet still makes the apps available in your shell: pipx creates an isolated environment for each application and its associated packages.

    By design, such applications will not be importable from other Python environments. If you want to install libraries into an existing environment, use pip, Poetry, Hatch, or any number of other tools.