小能豆

How do I get my code from Jupyter Lab to format properly on GitHub (very new to git)

py

This is what my code looks like when I push it to github via my command line. Although I’m just glad it pushed at all, I would like it to be in a format easier to read. Is there any efficient way to do this or is github just incompatible with Jupyter Lab?

I tried to run a command I found online:

conda create -y -n patagonia python=3.8 
conda activate patagonia
conda install -y -c conda-forge pylint black jupyterlab jupyterlab_code_formatter

but I wasn’t sure exactly where to run it nor what it actually does.


阅读 74

收藏
2023-12-23

共1个答案

小能豆

It seems like you are trying to set up a Conda environment and install some tools for code formatting in Jupyter Lab. The commands you provided are intended to be run in your terminal or command prompt, not within a Jupyter Notebook or Jupyter Lab cell.

Here’s a breakdown of what those commands do:

  1. Create a Conda environment named ‘patagonia’ with Python 3.8:

conda create -y -n patagonia python=3.8

  • -y: Assume yes and silently install.
  • -n patagonia: Specifies the name of the environment.
  • python=3.8: Specifies the Python version for the environment.

  • Activate the ‘patagonia’ Conda environment:

conda activate patagonia

This command activates the specified Conda environment.

  1. Install packages into the ‘patagonia’ environment:

conda install -y -c conda-forge pylint black jupyterlab jupyterlab_code_formatter

  • -c conda-forge: Specifies the Conda Forge channel as a source for packages.
  • pylint black jupyterlab jupyterlab_code_formatter: Installs the specified packages.

Now, for the readability of Jupyter Notebooks or Jupyter Lab, you can use tools like black and jupyterlab_code_formatter to automatically format your code cells.

After you have set up your environment and installed the necessary tools, you can use the following commands to format your code in Jupyter Lab:

jupyter nbextension enable --py widgetsnbextension
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install @ryantam626/jupyterlab_code_formatter

After running these commands, you should be able to use the “Code Formatter” option in the Jupyter Lab interface to format your code cells. Additionally, make sure to select the ‘patagonia’ environment when running your Jupyter Lab.

Remember that you should run these commands in your terminal or command prompt, not within a Jupyter Notebook or Jupyter Lab cell.

2023-12-23