Search code examples
pythonformatter

I have installed "black" in virtual environment using pip, but when I run python -m black my_module.py , it says No module named black


I have installed black Python code formatter using 'pip install black' in my virtual environment. But when I run '''python -m black output.py --check''', output is like this ''' /usr/bin/python: No module named black. '''. How to correct this error?

I'm getting same error outside virtual environment as well.


Solution

  • As you have mentioned, you installed black to a virtual env. But your output says /usr/bin/python which probably means that the virtual environment is not activated.

    Try activating it with source {YOUR_VENV_ROOT}/bin/activate, if you are using python-virtualenv, or activate it by other means, and try again.

    You can also access your venv by executing your local python executable: {YOUR_VENV_ROOT/bin/python -m black output.py --check