Code works in Spyder, not in Jupyter notebook - jupyter-notebook

I have a piece of code that looks like it should work just fine. When I run it in jupyter notebook (v3.8.8) I get this - TypeError: 'list' object is not callable
I'll run the same code in Spyder (v4.2.5) and it works exactly as it should. Is there some compatibility issue or something going on? Have any advice as to why it would work on one platform and not another? Is there anything I can do to circumvent this so it works on my jupyter notebook?
# Grocery list and prices
food = ["Tostino's Party Pizza", "Lay's Classic Potato Chips", "Pepsi Soda, 2 Liter", "Tyson Any'tizers Chicken Wings"]
price = [1.50, 3.98, 1.98, 10.42]
#Calculating sum of groceries
total_price = []
for p in price:
total_price.append(p)
print(total_price)
print(sum(total_price))

So...someone from my class took a look at this and said the code should work as its written. They said running both Jupyter notebook and Spyder at the same time may be causing issues with the kernels. She suggested I interrupt the kernel at first, but that didn't work. Next, we tried to restart the kernel and run the code again, and it worked. I don't understand how these things work, but I'm glad I can get on with life now...

I was stuck with a similar error but that was for 'generator' type. It was running fine in Spyder but not in Jupyter notebook. Spent two hours to understand the issue and finally after reading the note of redleg_64, just restarted the Kernel in Jupyter and it worked!

Related

%debug magic command not working in the Q# Jupyter Notebook environment

As per the documentation provided by Microsoft Azure Quantum at this link , I followed the steps given and installed Q# with Jupyter Notebook, using Anaconda.
I then wrote the following Q# program in a Jupyter Notebook (IQ# kernel) using the code taken from here.
(I am currently using Google Chrome)
open Microsoft.Quantum.Diagnostics;
operation MultiQubitDumpMachineDemo() : Unit {
use qubit = Qubit();
H(qubit);
DumpMachine();
Reset(qubit);
}
When I used the magic commands such as %simulate and %trace, the program executed normally. The DumpMachine result clearly shows the qubit in a superposition of |0> and |1> (measurement probability is 50%), and the trace command printed out the quantum circuit.
%simulate Result
%trace Result
However, when I run the %debug command, the interactive HTML display does not work. The debug control button can display the circuit but, the controls for the chart options do not display the amplitudes, probabilities, or real/imaginary co-efficients.
When I opened the console, I observed the following error, every time I clicked the chart options controls:
Couldn't process kernel message TypeError: state.getDenseAmplitudes is not a function
at fitChart (bundle.js?v=20221015232727:292:32)
at Object.updateChart (bundle.js?v=20221015232727:277:9)
at update (bundle.js?v=20221015232727:811:32)
at bundle.js?v=20221015232727:850:17
at Kernel._handle_iopub_message (main.min.js?v=a4e125c812cb3975203ae429a5b40d180b59b8e4602fcc78390ef4f0dd4d14ac3559189f65f23cd50fd971f98f5842b7746f4182babd20b7ca84e52314bcd4ac:63064:20)
at Kernel._finish_ws_message (main.min.js?v=a4e125c812cb3975203ae429a5b40d180b59b8e4602fcc78390ef4f0dd4d14ac3559189f65f23cd50fd971f98f5842b7746f4182babd20b7ca84e52314bcd4ac:62843:29)
at main.min.js?v=a4e125c812cb3975203ae429a5b40d180b59b8e4602fcc78390ef4f0dd4d14ac3559189f65f23cd50fd971f98f5842b7746f4182babd20b7ca84e52314bcd4ac:62834:44
Error Message
Unfortunately, I am not familiar with this type of error or its possible solutions, so I didn't try anything more than updating the 'iqsharp' package.
Can anyone explain why I'm getting this error, and, if possible, provide with me a solution for the same?
Thanks in advance!

Greek Characters in Julia Jupyter edition

I am using Julia.
I am trying to get some greek characters in Jupyter notebooks.
First I downloaded the latest version of Julia 1.6.2
For the jupyter connection I used anaconda, in julia repl i put ] add IJulia, and then I could chose the Julia kernel in Jupyter.
Then a friend suggested to download vs code (since we got a problem in the working directory with jupyter-anaconda)
In VS code we got no problem with working directories. And to work with notebooks we installed the Jupyter extension. It was working very well, but we got to this problem that we cannot get greek characters.
In Jupyter (anaconda) I could easily put greek characters, like this:
no package needed, nothing, just like that.
However in VSCode I cannot get that, nor "predictive text" or coding suggestions:
Any tips on how to solve this?
Like we are preferring VS Code and we know there's a way to get the greek characters on it, but we don't know how.
Any help is very welcomed.
Thanks in advance.
Check out the docs for the Julia extension in VS code here: https://code.visualstudio.com/docs/languages/julia. Per the comments above, make sure this is installed and you have the Julia kernel selected. You should then see the following:

R studio console suddenly does not show output

here are my console output examples
as you see, there are no output values when using r studio console.
Actually, there are many related issues about this, but no clear solutions. Only a temporal or Adhoc solution like: restart R or using r notebook script.
Anyway, this phenomenon happens just 1 day ago, with the same code, same operations.
At the first time, console works and a few minutes later it doesn't work.
It is so annoying me to restart or run r notebook script...
Is anybody have the same issues as me?
(I cannot give reproducible data, because it works well the other's computer)
Click on the gear icon beside knit and make sure that "chunk output in console" is enabled.

How can I run multiple lines of code in R

I have just switched from windows 7 to windows 10 on my pc.
When I was still using windows 7, using the combination CTRL+R or CTRL+ENTER would run the line of code that I was in. Moreover, if the code continued on one or more lines below or started above my current line, it would run the entire section without me having to select it.
After switching to windows 10, the same combinations will only run the line of code that I am currently in, or the piece of code that is selected by me. To give an example:
#Tryout
for(i in 1:3){
print(i)
}
This code would normally run at once without having to select it, even when I would start in the first line (#Tryout). Now, if I don't select, I will need to use CTRL+R or CTRL+ENTER three times to go through this code and I have to start in the correct line. Starting in the line #Tryout will not run any part of the code but will only result in the line #Tryout being shown in the console.
I'm not good with computers (in your answers please pretend to be adressing a five-year-old) so I had one of my colleagues look at it who's our expert on R. Here are the findings:
The problem occurs in both RStudio as the standalone version of R.
I'm using R version 3.3.2, the same as before the windows update. Switching to version 3.5 didn't solve the problem.
I have other colleagues also using R 3.3 in combination with windows 10 for whom this problem does not occur.
Going to Tools-Global Options-Code and checking the box of 'Focus console after executing from source' doesn't help
When we went to 'Modify Keyboard Shortcuts', the name attached to the shortcut (CTRL+R or CTRL+ENTER) was the same as it was for other colleagues for which the function does run all lines in a command: 'Run Current Line or Selection'
The problem is not preventing me from using R, but it is tedious and I hope someone can help me to solve it.
Thanks so much for reading!
Click on header Tools, then Global Options..., then Code, then Ctrl + Enter Executes and choose Multi-line R statement
#M Waz & #Just Burfi: I know I can select the code and then run it, that works fine. But I don't want to have to manually select the code all the time.
#Clemsang: your answer puzzled me for a moment because I didn't have the CTRL + Enter Executes that you were referring to. I went back to my colleague who had the bright idea to check the version of RStudio that I was using.
As it turns out, I was using an old version (0.99.903). Now that I've installed a newer version (1.1.463), running the code works as before! I also have the CTRL + Enter Executes now.

Atom and Hydrogen: Output and console

I'm a Python beginner and recently came across the Atom editor and the package Hydrogen, that implements the Jupyter notebook. I did so after realizing that running the notebook in Chrome consumed way too many resources and also seemed to be a bit slower.
However, the Atom editor and Hydrogen always output prints within a little frame in the code (see image). Unfortunately, it doesn't use the full window width. I also don't see any console/terminal for installing pip libraries.
Is there a way to have the output in a console below the code, just as in Jupyter, and to have a terminal?
this comes most certainly too late, but in case someone else searches for this:
hit control+shift+P / cmd+shift+P and type "toggle output area".

Resources