Python Forum
How to use nb-black python cde formatter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use nb-black python cde formatter
#1
I have used the python code formatter nb_black. I have not used it in about a year. I have some python code that needs formtting. I am always a little unsure of the python format so I let nb_black do it. It usually works.

Now when I try to install nb_black using

pip install nb_black

I get the message that the file nb_black does not exist. However, I can stall nb-black. Notice the position change: the underscore now becomes a dash. I am not sure if they are the same. One works and the other does not. Neithr works today.

When I put the line

%load_ext nb-black

at the top of the program's code it does not do anything. Of course, as I said before, I installed it via

pip install nb-black.

What am I doing wrong? If there is a better python code formatter pleae let me know.

I am using a jupyter notebook on Ubuntu with python 3.7.7.

Any help appreciated. Thanks in advance.

Respectfully,

ErnestTBass
Reply
#2
Hi

this link takes you to PiPy (https://pypi.org/project/nb-black/) and gives instruction on how to install the package you mention, if it fails to do so then me i would probably wonder if the package was worth it now and if you are just looking for a code formatter for python then there is a plethora of choices! Personally i like PyCharm as it not only formats but enforces by default PEP standards of line spacing etc etc, another would be Visual Source Code (VSC) which has its own pros too like being able to add plugins for other extensions, docker, mongdb....loads
Regards
-------- *
“Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.”
Reply
#3
(Jun-03-2020, 11:38 AM)ErnestTBass Wrote: I am using a jupyter notebook on Ubuntu with python 3.7.7.
We have talk a lot about setup and environment in your previous Thread.
If you use Anaconda as in your other post,most remember to activate base.
Then test with pip -V and it should now point to the Anaconda placement.
Here a quick test on Windows now,could do the same on Linux no difference.
G:\Anaconda3
λ G:\Anaconda3\Scripts\activate

(base) G:\Anaconda3
λ pip -V
pip 20.0.2 from G:\Anaconda3\lib\site-packages\pip (python 3.7)

(base) G:\Anaconda3
λ pip install nb-black
Collecting nb-black
.....
Successfully built nb-black
Installing collected packages: nb-black
Successfully installed nb-black-1.0.7

(base) G:\Anaconda3
λ jupyter lab
[I 17:11:58.129 LabApp] JupyterLab extension loaded from g:\anaconda3\lib\site-packages\jupyterlab
So no have installed nb-black and start jupyter lab all in base environment.

Test
%load_ext lab_black  

def foo():
 return 42

thisdict = {"brand": "Ford", "model": "Mustang", "year": 1964, "brand": "Bmw", "model": "M3", "year": 1980} 
Run cell:
def foo():
    return 42


thisdict = {
    "brand": "Ford",
    "model": "Mustang",
    "year": 1964,
    "brand": "Bmw",
    "model": "M3",
    "year": 1980,
}
So if work as expected black dos it's job and formatting the code in NoteBook.
Reply
#4
I am using a Docker container for my Python Code with a Jupyter Notebook.

There is only the base environment. I had a conda virtual environment, but I removed it. I should not have to activate my base environment, if it is the only one on the system.

I would love to use Pycharm, but as I said I am using a Docker container. Can Pycharm work with a Docker container?

It took some doing to get the jupyter notebook to work in a Docker container. I thought this may be the same type issue.

Any help appreciated. Thanks in advance.

Respectfully,

ErnestTBass
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  remove all color but red, then replace it with black kucingkembar 14 7,126 Dec-29-2021, 07:50 PM
Last Post: deanhystad
  VS Code Python Formatter muzikman 6 2,915 Sep-16-2021, 04:40 PM
Last Post: DeaD_EyE
  Checkbuttons always come up as black boxes regardless of the state kenwatts275 5 4,732 Jul-07-2020, 08:00 PM
Last Post: kenwatts275
  Finance: Black Scholes Model not working pwt 5 3,934 May-27-2020, 10:14 AM
Last Post: buran
  after using openpyxl to add colors to script, black shows up white online in excel Soundtechscott 1 3,697 Jun-08-2019, 10:33 PM
Last Post: Soundtechscott
  Because the emoji appears black and white at the exit ? nerd 3 5,606 Jan-28-2019, 11:34 PM
Last Post: nerd
  Python interface only black and white........ Wilson 3 6,164 Jul-15-2017, 01:20 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020