16

I want to remove the Jupyter "Run Cell|Run All Cells" buttons that appear if the syntax #%% is present in Visual Studio Code.

vsc

Is there a setting that controls that?

4 Answers 4

11

You can toggle off Python>Data Science: Enable Cell Code Lens settings.

Screenshot from settings

Sign up to request clarification or add additional context in comments.

1 Comment

Just to add, this disables the "Go to <output>" cell lens, and there doesn't seem to be any command that would provide the same functionality.
2

If you turn off the data science features (the Python Interactive window) under Settings>Python>Data Science>Enabled then you won't see those code lenses any more. However that will also hide the rest of the data science features along with the lenses. Were you looking to turn off all data science features in the python extension or just the lenses?

5 Comments

Thank you for your response. I was looking to turn just the lenses (if that is what is it called). Just the 'Run Cell | Run All Cells' emblem.
Sorry Domen, there isn't currently a way to turn off just the lenses. If you want you could file an issue here on our GitHub: github.com/Microsoft/vscode-python/issues. Personally that seems like it could be a reasonable option for folks who don't want the visual clutter in their files.
There used to be a way to do this... now I cannot find it. I'm not seeing the Settings>Python Data Science features you're talking about, can you elaborate?
Found it! "jupyter.enableCellCodeLens": false
Now it seems to be "jupyter.interactiveWindow.codeLens.enable": false
2

Update for others coming to this question:

With recent update you can choose what's displayed Run cell |...". If you're looking to remove clutter delete everything and save like below:

enter image description here

I would recommend leaving at least python.datascience.runcell as it seems to disable shift+enter shortcut

1 Comment

Disabling the lenses seems to disable the commands as well. What the heck is that about?
-2

Save the code snippet below as : remove_inline_comment.py
Assuming your filename as : sample_file.py,
RUN : python remove_inline_comment.py sample_file.py

[ NOTE : Make sure both of these files are in same folder ]

import argparse
import os
import sys
import re


def process(filename):
    """Removes empty lines and lines that contain only whitespace, and
    lines with comments"""

    with open(filename) as in_file, open(filename, "r+") as out_file:
        for line in in_file:
            if re.match("# In\[[0-9\\d+\]]", line):
                out_file.write("\n")
            else:
                out_file.writelines(line)


if __name__ == "__main__":

    my_parser = argparse.ArgumentParser(
        description="Removing the In#\[[0-9\d+\]] in notebook to script conversion"
    )

    my_parser.add_argument(
        "script_path",
        metavar="path",
        type=str,
        help="path to script that requires a conversion",
    )

    args = my_parser.parse_args()
    script_path = args.script_path

    file_format = script_path.split(".")[1]
    if file_format != "py":
        print("File is not a py file")
        sys.exit()

    try:
        print(f"processing : {script_path}")
        process(script_path)
    except FileNotFoundError:
        print("Please provide path correctly")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.