'Kernel died with exit code 1' Error with Jupyter Notebook in VS Code - visual-studio-code

I am trying to run a Jupyter notebook in VS Code but I keep getting this error code:
I have Python 3.8.8 which was installed using Anaconda. The project folder has a virtual environment created using venv. I tried the solutions given here but none worked.

Related

Why has Jupyter notebook kernel stopped working after RStudio package installation

To date I have been using Jupyter Notebook to run R and sometimes Python code. I have also been using RStudio at times. Recently, while using RStudio, I was prompted to install some package (cannot exactly remember). At any rate, I installed this package. Dont know if only coincidence, but trying to run R in the notebook resulted in kernel not connecting. I found the same issue with Python, the Python kernel is also not connecting anymore.
Executing the below, I get;
(base) C:\WINDOWS\system32>jupyter kernelspec list
Available kernels:
ir C:\Users\Admin\AppData\Roaming\jupyter\kernels\ir
python3 C:\Users\Admin\anaconda3\share\jupyter\kernels\python3
How do I get Jupyter Notebook's kernels to work again.
Executing IRkernel::installspec() in R via Anaconda CMD prompt have resolved the issue. Note for others with this issue, you may be prompted to run install.packages(“rlang”) before.

After the latest update of VSCode, I can't run Jupyter notebooks anymore

After updating VSCode, I have been unable to run Jupyter notebooks anymore. I am using VSCode on a MacBook Pro Max M1 and am encountering the following error:
Failed to start the Kernel.
Jupyter server crashed. Unable to connect.
Error code from Jupyter: 1
usage: jupyter.py [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
[--paths] [--json] [--debug]
[subcommand]
Jupyter: Interactive Computing
positional arguments:
subcommand the subcommand to launch
options:
-h, --help show this help message and exit
--version show the versions of core jupyter packages and exit
--config-dir show Jupyter config dir
--data-dir show Jupyter data dir
--runtime-dir show Jupyter runtime dir
--paths show all Jupyter paths. Add --json for machine-readable
format.
--json output paths as machine-readable json
--debug output debug information about paths
Available subcommands: kernel kernelspec migrate run troubleshoot
Jupyter command jupyter-notebook not found.
View Jupyter log for further details.
Unfortunately, none of the steps I tried have worked.
I am using January 2023 (version 1.75) release and extesion versions are as follows:
Python v2023.2.0
Jupyter v2023.1.2010391206
Has anyone else faced this issue? I would greatly appreciate any suggestions or solutions.
Thank you!
I have tried a number of steps to resolve the issue, including:
Making sure that jupyter-notebook is running in the terminal
Installing Jupyter in new conda and Python virtual environments
Removing VSCode and its related directories completely and downloading it again
Trying the "Switch to Pre-Release Version" for both Jupyter and Python extensions in VSCode
Tried updating jupyter and notebook liberaries
Tried running VSCode with code --no-sandbox
solved downgrading to previous version (November 2022) then updating to latest version again. Running same Python and Jupyter version. Good luck
I ran into this too. I was able to work around it by switching the Jupyter extension to the pre-release version (which was a suggestion in a different question that I can't find anymore).

how to use qutip in visual studio code?

I am a beginner of QuTip (a library of python?) user. I have already installed my qutip in my environment by conda. I can execute simple program in jupyter book but not in VScode. How can I do it in VScode?
What I tried:
import qutip
qutip.about()
However the result shows:
AttributeError: partially initialized module 'qutip' has no attribute 'about' (most likely due to a circular import)
I tried executing it by Jupyter book and Anaconda prompt and they work. So why or how can I use it in Visual Studio code?
Note: I open Anaconda prompt, go into my python environment which I install qutip and execute above script.
Note2: I followed the installation steps here: https://qutip.org/docs/latest/installation.html#installing-with-conda
Note3: In visual studio code, I use command line to call my python environment which I installed qutip (I have set Path variable when I installed Anaconda) and execute above scripts.

"Running cells requires Jupyter notebooks to be installed" error in VS Code

I'm trying to use the new Jupyter integration for the Python extension in VS Code, and I'm getting the above error even though I have Jupyter installed and it works fine from the command prompt.
Here's my environment:
Python extension version 2018.10.1, and I see Run Cell/Run All Cells tooltips above #%% comments.
I've used the Python: Select Interpreter command to select my Anaconda environment, which is at ~/AppData/Local/Continuum/anaconda3/python.exe.
I have Jupyter installed in that interpreter (jupyter.exe is in the Scripts sub-folder under that location), and it runs fine with the jupyter notebook command at the Anaconda prompt.
But whenever I click on Run Cell or press shift-enter, I get this error message:
"Running cells requires Jupyter notebooks to be installed." Source: Python (Extension)
Is there something else I need to do to configure this?
You may give one try by restarting VS Code in following mentioned way [ It worked for me. ]
Open Bash or any other cmd
Activate any conda environment [ See below command ]
source activate base [ means activate base environment ]
Run VS Code instance [ See below command ]
code .
Now when you'll click on Run Cell or press shift-enter, it should work.
The problem is an issue in the VS Code python extension itself. There are a number of issues related to this open in the repository: #3354, #3343, #3330, and the issues are being worked on, see #3374.
The reason, as far as I understand, is that in this case - and in some other cases - the anaconda environment is not activated before running the command. Situations where the environment is activated are e.g. opening a python terminal or running a file in the python terminal, but this also needs to happen for Jupyter, Tests, and so on.
While theoretically, adding the Scripts folder to your PATH, as David mentioned, could help, it did not help in my case. This may just not be enough to properly reflect what happens on activation.
My guess is that we will have to wait for this issue to be resolved in the repo, but if someone else finds a workaround, I'd be happy.
Simply running vscode from the activated environment did not work for me, here is what did:
In terminal (bash) I ran:
conda activate <environment-name>
conda install jupyter notebook
When the install finishes, open vscode from terminal (the same shell with activated environment) with the command:
code .
Notes:
Replace '.' with the path to the directory you want to open if it's not the current directory.
I've written 'conda install ...' but mamba also works.
If the terminal command for 'code ' does not work, it's likely you need to add it to environemnt variables; in such a case, this post might help.