Search code examples
pythonpre-commit

python run pre-commit with -m


Python modules can be run with -m for example next command for pip

python3.10 -m pip install pre-commit

It allow you to specify exact python binary to use with command (python3.10 or python3.11).

I have successfully installed pre-commit, but got next:

python3.10 -m pre-commit run         
> python.exe: No module named pre-commit

python3.10 -m precommit run  
> python.exe: No module named precommit

how to run pre-commit via python -m option ?


Solution

  • The module name is pre_commit, not pre-commit (which is the name of the entry point), so you need to run

    python -m pre_commit
    

    Note the different names that can be set and do not neccessarily have to be the same:

    1. The name of the PyPi project, which is what you use with pip install
    2. The name of the python module, which is the name used with import from within a script or when you do python -m
    3. The name of an entry-point defined in setup.cfg or an executable that is placed in the bin folder during setup, which is a name that you can directly type in your terminal