5 votes

Python noob having trouble installing black

So, the black installation doc tells me to install black by using: pip install black

I don't know what pip is so I go read about it here. These instructions tell me that pip is already installed since I have the latest version of Python installed.

That's wonderful, right?

Not for me. How do I install black?

Black can be installed by running pip install black.

Do I run this from the Terminal (I'm using Mac)?

13 comments

  1. [7]
    tesseractcat
    Link
    Pip is a package manager for python modules that ships with python. Depending on how you installed it, you can execute it via pip, pip3, python3 -m pip, or python -m pip. Most likely it will...

    Pip is a package manager for python modules that ships with python. Depending on how you installed it, you can execute it via pip, pip3, python3 -m pip, or python -m pip. Most likely it will simply be pip. You would run this from the terminal, since pip is a command line program.

    10 votes
    1. [6]
      suspended
      Link Parent
      python3 -m pip install black That was the winner. Thanks!

      python3 -m pip install black

      That was the winner. Thanks!

      8 votes
      1. [3]
        teaearlgraycold
        Link Parent
        If you can't find a pip3 binary anywhere on your system you could, worst case, add this to your ~/.bashrc: alias pip="python3 -m pip" Look for a pip copy with this command: find / -name pip* 2>...

        If you can't find a pip3 binary anywhere on your system you could, worst case, add this to your ~/.bashrc:

        alias pip="python3 -m pip"
        

        Look for a pip copy with this command:

        find / -name pip* 2> /dev/null
        
        5 votes
        1. suspended
          Link Parent
          I'm a complete noob to command line use, jargon, etc. On the other hand, I think I understand what you are saying. Thanks for the helpful comment!

          I'm a complete noob to command line use, jargon, etc. On the other hand, I think I understand what you are saying. Thanks for the helpful comment!

          3 votes
        2. emdash
          Link Parent
          He's on a Mac, so more correctly he'd want this in ~/.bash_profile, so a symlink or a source from ~/.bashrc are both acceptable alternatives.

          He's on a Mac, so more correctly he'd want this in ~/.bash_profile, so a symlink or a source from ~/.bashrc are both acceptable alternatives.

          1 vote
      2. [2]
        Elronnd
        Link Parent
        Hi. Don't do what the sibling comment says. Instead, run this once: python3 -m ensurepip After that, you should be able to run pip or pip3 by itself, so pip install black would work. Good luck,...

        Hi. Don't do what the sibling comment says. Instead, run this once:

        python3 -m ensurepip
        

        After that, you should be able to run pip or pip3 by itself, so pip install black would work.

        Good luck, and have fun!

        2 votes
        1. suspended
          Link Parent
          Here's what I got from running this: Looking in links: /var/folders/tb/f9c2wgsd6ygcsj0krjs7jwp00000gn/T/tmp9w9ok8nj Requirement already satisfied: setuptools in...

          Here's what I got from running this:

          Looking in links: /var/folders/tb/f9c2wgsd6ygcsj0krjs7jwp00000gn/T/tmp9w9ok8nj
          Requirement already satisfied: setuptools in /usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (40.8.0)
          Requirement already satisfied: pip in /usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (19.0.3)
          
          3 votes
  2. [3]
    apoctr
    Link
    Although there's already a few sufficient answers, to provide some additional information: like pip, the black tool must (as far as I'm aware) also be run from a terminal. So you'd need to learn...

    Although there's already a few sufficient answers, to provide some additional information: like pip, the black tool must (as far as I'm aware) also be run from a terminal. So you'd need to learn some basic shell navigation if you're not comfortable with that (mostly just cd and ls), and run black . from the directory containing your program.

    6 votes
    1. suspended
      Link Parent
      OK. Thanks for the additional information.

      OK. Thanks for the additional information.

      1 vote
    2. gco
      Link Parent
      Not sure if it's possible in other editors, but I've set up Atom so every time I save it runs black on the file.

      the black tool must (as far as I'm aware) also be run from a terminal

      Not sure if it's possible in other editors, but I've set up Atom so every time I save it runs black on the file.

      1 vote
  3. [2]
    PetitPrince
    Link
    In addition to the other answer, notice that some editor can directly integrate Black (or other code formatter such as yapf, autopep8, etc) within their interface. For instance, if you are using...

    In addition to the other answer, notice that some editor can directly integrate Black (or other code formatter such as yapf, autopep8, etc) within their interface.

    For instance, if you are using VS Code and have installed the python extension and set Black as the code formatter, you can then use the format option and have the text directly replaced in the editor.

    4 votes
    1. suspended
      Link Parent
      Anyone know how to integrate black with PyCharm?

      Anyone know how to integrate black with PyCharm?

      1 vote
  4. Soptik
    Link
    Yes. Pip is a program, just like python, or firefox. Just as every other program, you can start it from the terminal (actually, you can start many programs just from the terminal). Running pip...

    Yes.

    Pip is a program, just like python, or firefox. Just as every other program, you can start it from the terminal (actually, you can start many programs just from the terminal).

    Running pip install black in terminal should be enough.

    2 votes