Search code examples
pythonpipmodulepackage

Is there a way to check all the python modules that are currently installed that can be accessed directly from the terminal?


Some python modules like pip, venv, streamlit, etc can be accessed by directly typing them and hitting enter in the terminal.

I recently started using pip-tools and although pip-tools can be seen listed in the output of pip freeze, the actual commands that can be accessed from the terminal directly are pip-compile and pip-sync and not pip-tools. Neither are pip-compile and pip-sync listed in the output of pip freeze.

This has me wondering how to list down all such python modules that can be accessed from the terminal directly because clearly pip freeze does not list everything. I did some basic digging on the internet but only found stuff that tells me do pip freeze. So, how to check what are the options I have when it comes to accessing python modules directly from the terminal?

TL;DR, I tried doing pip freeze but pip-compile and pip-sync are not listed and only pip-tools is but you can only use pip-compile and pip-sync as a command directly in the terminal.

This is not a question about how to use pip-tools but what is the way to list down all the available python modules that can be accessed from the terminal directly in a particular environment.


Solution

  • pip-compile and pip-sync are not python modules or pacakages themselves, but rather scripts/commands that are distributed by pip-tools (you can see this declared in pip-tool's pyproject.toml file).

    To see python packages in your current environment you can run pip freeze (assuming you are doing package management with pip and not something like poetry). In your example you will not see pip-compile or pip-sync because these are commands and not packages.

    To see commands that are in your current PATH and are distributed by python packages I just generally use ls (this assumes you're on Linux or Mac OS). It's a bit more straightforward when using a virtual environment because everything is self-contained and you can run something like (substitute in the real path to your virtualenv here):

    ls ~/venvs/my_awesome_venv/bin
    

    If you're not in a virtualenv but instead have packages installed user or system-wide, try running which python3 to grab the path to the python interpreter, and then ls that directory. There will be a bit more to sort through, but this will get you closer.