I am trying to build a Chatbot using Jupyter Notebook on Google Colab. I am using IPython Markdown to better segregate the user conversations. User will key in their message using input() while the bot responses are IPython display(markdown()).
I am facing issues when i tried to print a starting messages (bot output before a user input). This error occurs approximately 50% of the time I run the script. No errors are faced if I did not print out the starting message. I have tried restarting the kernel but to no avail.
Does anyone know what is the reason for this and how I can fix it?
This is an example of a successful case.
This is an example of a failed case. As you can see, the code is running indefinitely on the input() line.
This is the sample code, where input() box does not pop up at times.
from IPython.display import Markdown, display
display(Markdown("*Alex:* Hello."))
input(">> You: ")
This seems to be a kind of bug in Jupyter notebook, described in the past years by many programmers. I was facing the same problem. After several tests I have found (at least in my code) that the problem disappears if print() functions are removed before input().
Related
Whenever I use the function pylab.plot(), it causes spyder to crash and show an error
This is the code I'm using:
def myplot():
x = ([1,2,3],[2,4,6])
pylab.plot(x)
This is the error message I've got:
Error Message
My friends are running the exact same code without an error - I can't work out what I'm doing wrong?
Every time this happens I have to open a new console to make spyder even function which needless to say is extremely irritating.
I'd appreciate any help, thank you,
Ben
I want to be able to autohide code cells after they have run once in a jupyter notebook.
I am calling a function that prints some output. For example
print("Hello World")
The problem I am trying to solve is that after the output is printed, the code block stays there. I can use ctrl k + ctrl o to hide the code block after execution however there are many code blocks like that and I want it to be automatic. I tried using some javascript (https://habr.com/en/post/439570/) however that didn't work as expected. I am aware that I can use NBconvert to hide all the code cells while generating a pdf however I want only some cells to be hidden and that to in the raw notebook.
I looked into how we can add metadata in the cell to hide it with python here: https://jupyterbook.org/content/metadata.html
However, I want to do it locally on some cells, and I want to prevent file changed, do you want to overwrite your notebook prompts.
Is this possible?
For Vscode, refer to the official documentation https://code.visualstudio.com/docs/datascience/jupyter-notebooks, however I couldn't find anything related to autohide/collapse when using Vscode. They might release this functionality in their next release.
I'm using jupyter 4.1.0, and I find myself making frequent use of the "Restart & Run All" feature. Every time I use that button it displays this warning:
Is there a way to disable that warning?
You can add a cell in your notebook and using the following statements:
from IPython.core.display import HTML
HTML("<script>Jupyter.notebook.kernel.restart()</script>")
And the kernel will restart immediately.
To answer the question that was stated: No, there isn't.
But you might make your voice heard over here so they might implement it some day.
You can create a bookmark in your browser for the following code:
javascript:Jupyter.notebook.execute_all_cells();void(0);
Clicking this bookmark runs all cells without asking for confirmation.
I am trying to run a program on a jupyter notebook that accepts user input, and I cannot figure out how to get it to read standard input. For example, if I run the code with shift-enter:
a = input()
print(a)
the cell indicates it is running, but does not accept input from me. How do I get it to accept input?
Use the raw_input() (for Python 2) or input() (for Python 3) methods.
Example code:
a = raw_input()
print(a)
Example notebook:
I came across the same problem, using the input in jupyternotebook, it blocks the execution and it does not work until restarting the program, so I added a print () after each input and my program is working.
Probably you hit Shift-Enter a second time without completing the first input with Enter, so the kernel was always waiting until the first command completed, before executing it again. If you use in the menu
"Kernel",
"Interrupt",
all active commands are stopped (including the second execution of the box) and the problem should be solved without restarting the computer (or the browser / the kernel).
You are doing it right, you ony have to restart the kernel (over the Run button)
use raw_input instead of input if you are using python 2 version. if u still getting same problem then,
click on kernel then "restart and run all"
and try to run the code again.
this will fix it.
I have recently started to learn Python 3 and have run into an issue while trying to learn how to debug using IDLE. I have created a basic program following a tutorial, which then explains how to use the debugger. However, I keep running into an issue while stepping through the code, which the tutorial does not explain (I have followed the instructions perfectly) nor does hours of searching on the internet. Basically if I step while already inside a function, usually following print() the debugger steps into pyshell.py, specifically, PyShell.py:1285: write() if i step out of pyshell, the debugger will simple step back in as soon as I try to move on, if this is repeated the step, go, etc buttons will grey out.
Any help will be greatly appreciated.
Thanks.
pyshell.py file opens during the debugging process when the function that is under review is found in Python's library - for example print() or input(). If you want to bypass this file/process click Over and it will step over this review of the function in Python's library.
In Python 3.4, I had the same problem. My tutorial is from Invent with Python by Al Sweigart, chapter 7.
New file editor windows such as pyshell.py and random.pyopen when built-in functions are called, such as input(), print(), random.randint(), etc. Then the STEP button starts stepping through the file it opened.
If you click OVER, you will have to click it several times, but if you click OUT, pyshell.py will close immediately and you'll be back in the original file you were trying to debug.
Also, I encountered problems confusing this one--the grayed-out buttons you mentioned--if I forgot to click in the shell and give input when the program asked. I tried Wing IDE and it didn't run the program correctly, although the program has no bugs. So I googled the problem, and there was no indication that IDLE is broken or useless.
Therefore, I kept trying till the OUT button in the IDLE debugger solved the problem.