Running Python file is greyed out on Jupyter Lite

Dear community,

I am new to using Jupyter Notebooks and am struggling to run a Python script. I just set up my account on JupyterLite. I copy-pasted the following code from Autovis to automatically visualise my data set but the option “Run” from the menu is greyed out, see here:

Is there a way to (1) get the “run” function working again? Also, is it possible or required to install the package first? If so, how can I do so on the Jupyter online environment?

Many thanks in advance for your help!

TL;DR:

Attach a console backed by a kernel to the script editor pane to activate the associated options in the ‘Run’ menu.



There’s no account to set up here and so I’m not sure what you meant by that.
Please pay close attention to the ‘Experimental’ warning on the page right above where you clicked to launch it on the main ‘Try Jupyter’ page here. The link you posted above in your original post launches JupyterLab in the browser of the person who clicks on it. What another person would get is entirely separate from your session in your browser. That is good for security, but means we cannot see “the following code” you reference.

It is working. Let’s separate out the issues here. Don’t use code you don’t know if it can run to debug something.

Step-by-step: running a test Python script in JupyterLite using the ‘Run’ menu:

  1. Launch JupyterLite’s JupyterLab interface. (If you have messed up your JupyterLite recently, I suggest opening it in incognito mode in your browser to get a fresh session. Keep in mind though it won’t be persistent in any way. [Always best to think of JupyterLite as not persistent anyway since it is in your browser that is essentially off limits to you and will change if you mess with your browser clear your cache.])

  2. Hit the blue ‘+’ sign button in the upper left side below the file menu. (From the screenshot, you show you’d have to hit the file folder icon on the left sidebar first to get the file navigator pane back as active first.)

  3. In the launcher pane, pick the ‘Python File’ tile under ‘Other’ in the lower middle or right side.

  4. In the Python file code editor, type print("Hello world.").

  5. Under the ‘File’ menu select ‘Save Python File’ and in the dialog box name it testscr.py and save it.

  6. Right-click anywhere in the Python code editor pane and select ‘Create Console for Editor’.(Optionally, you can right-click on the tab where you see the file name testscr.py and select ‘Create Console for Editor’.) That will attach a kernel to the editor with the console interface to interact with it. The ‘Run’ menu can now be used to execute code in this kernel.

  7. Go up to the ‘Run’ menu and from under it, select ‘Run All Code’. It will show the code it ran and the output in the console below.

  8. Optionally, you can select the code or part of it and run only that. For example, use the mouse to select only print("Hello wor part of the code, leaving off the end in what is highlighted in the selection. Go to the ‘Run’ menu and select ‘Run Selected Code’. That should show that it tried to run part of that line and hit a syntax error because not seeing the matching closing quotes. You can select the full line and run that the same way. Because this is all the code in the script at this time, it will then give the same result as seen with ‘Run All Code’.

There’s another option to run the script though. If developing in conjunction with a notebook, it can be very helpful:

Step-by-step: running a test Python script in JupyterLite using the Notebook:

  1. Launch JupyterLite’s JupyterLab interface. (If you have messed up your JupyterLite recently, I suggest opening it in incognito mode in your browser to get a fresh session. Keep in mind though it won’t be persistent in any way. [Always best to think of JupyterLite as not persistent anyway since it is in your browser that is essentially off limits to you and will change if you mess with your browser clear your cache.])

  2. Hit the blue ‘+’ sign button in the upper left side below the file menu. (From the screenshot, you show you’d have to hit the file folder icon on the left sidebar first to get the file navigator pane back as active first.)

  3. In the launcher pane, pick the ‘Python File’ tile under ‘Other’ in the lower middle or right side.

  4. In the Python file code editor, type print("Hello world.").

  5. Under the ‘File’ menu select ‘Save Python File’ and in the dialog box name it testscr.py and save it.

  6. Hit the blue ‘+’ sign button in the upper left side below the file menu and select under ‘Notebook’, select the ‘Python (Pyodide)’ tile.

  7. When that notebook opens, look in the upper right side and find the busy indicator that is the kernel status indicator and wait until it is empty circle so you are sure this is 100% ready to run code. (This step is important. You have to be patient before trying.) When the notebook first opens the circle will at first have a fill with lightning bolt saying it is busy and you need it clear before proceeding on.

  8. Enter in the cell int he notebook %run testscr.py.

  9. Execute the cell (you can hit the ‘play’ button on the toolbar above to do that) and you should see Hello world. as the output. You’ve now successfully run a Python script in JupyterLite.

I like this for development because if in the notebook, I had previously run a cell with a = 5, I can add print(a) to the second line of my testscr.py Python file and then use the interactive -i flag to now run the script in the same namespace as the notebook by running a variation of the %run command, in this example that would be %run -i testscr.py. This is nice for developing or stepping someone through setting up running something using the notebook. They can set things with cells in the notebook and then most of the code to process it can be over in a script to make it less overwhelming to those who are turned off by seeing code.
Also, because you talk about using autoviz, this may be a gateway to more feature-rich experience for running code from autoviz so that the notebook displays and stores the results in the notebook file upon saving.


Specifically about your post title

Your post is entitled ‘Running Python file is greyed out on Jupyter Lite’. That ‘Run’ menu is very context dependent. Given the many entries listed there is primarily for controlling run options when in the Jupyter notebook file when in the JupyterLab interface. It is not by default involved with running the script you happen to be editing in the code editor. Some of the options listed under the ‘Run’ menu can though be activated by attaching a console with an active kernel to the script. I have added a step-by-step example for this above. However, I wanted to include this section to give better insight into what you were experiencing originally.


Autoviz

Running %pip install autoviz in a notebook cell in JupyterLite gives the error Traceback that ends with:

ValueError: Can't find a pure Python 3 wheel for 'numpy<1.25.0'.
See: https://pyodide.org/en/stable/usage/faq.html#why-can-t-micropip-find-a-pure-python-wheel-for-a-package
You can use `await micropip.install(..., keep_going=True)` to get a list of all packages with missing wheels.

That means you cannot use autoviz with JupyterLite at this time because not all the dependencies have wheels it can use. See that link in the error for more about this. Note that in JupyterLite %pip install numpy will work and so it isn’t solely that numpy working in general per se that is the issue at this time. (From working with autoviz in MyBinder [see below], I see that it is very complex and has a lot of dependencies and so I suspect even if the numpy issue were addressed there may be other limitations quickly encountered if trying it in JupyterLite.)

Note I pointed out the ‘Experimental’ nature of JupyterLite at the start of this post. This is one of those rough edges at this time. I advise someone new to learning to use Jupyter Notebooks to start with a typical full Python kernel (ipykernel) and not JupyterLite which is using the Pyodide kernel. My reply to what I suspect is your post on SO here goes into details on how to do that for using autoviz.