Python: Use Jupyter kernel in VSCode - python

I am using Python 3 in Visual Studio Code (latest version).
I am wondering if there is a way to run Python scripts (in .py format) in VSCode adopting Jupyter Notebook as default terminal (instead of Powershell).
In a few words, I would like to make VSCode similar to Spyder IDE, which uses Jupyter Notebook as terminal and shows script variables in Variables Explorer.
Thanks in advance.

Using Jupyter extension you can create notebooks and interactive windows.
By clicking the Variables icon in the top toolbar after running code and cells, as mentioned on vscode documentation, you can view your variable explorer.

Related

The variables created using jupyter (.ipynb) do not work on .py files in vscode (in the same environment in WSL). Different terminals?

Context: I'm using vscode with WSL and I also use conda for environment management.
I'm trying to create a variable in a jupyter notebook, let's say x = [10, 20], and then use that same variable in a .py file (not on jupyter notebooks). I'm already using the same environment on both, but the terminal/kernel I believe is different for each. I believe this because when I run a cell on jupyter notebook, nothing happens on the terminal. However, when I run on .py files, the terminal runs the code I selected.
I would like to see the terminal running something for jupyter (.ipynb) and also for my .py files.
Any help would be really appreciated.

Why is VSCode running the wrong jupyter server?

macOS v. 11.2.3.
2 versions of python installed
/opt/homebrew/bin/python3
/usr/bin/python3
I created a virtual environment (venv) to work with a jupyter notebook, but every time I open a document in a VSCode, I see 2 servers start up at the same time and the last one that is selected is not the one that is in the virtual environment:
Moreover, every time I open a document, I have several files in the trash with something like this name:
chunks-3a679475-8ceb-44eb-9ac3-fcefe0595bc1.ipynb
How can i fix this?
In VS Code, it is normal that the python environments of the two are different. The python kernel used by Jupyter Notebook can be independent of the python environment selected in the lower left corner of VS Code, and usually it is the python environment used by VS Code by default. If the python extension has not been loaded yet, Jupyter uses the last python environment by default.
Please click on the location of the python kernel displayed on the upper right of Jupyter, and select the one you need from the expanded options. In addition, please try to reload VS Code.
Reference: Working with Jupyter Notebooks in Visual Studio Code.

How to code Matlab in VSCode via Jupyter Notebook?

My Jupyter kernel is running well since I can do Matlab jobs using a 'browser jupyter notebook' as well as when I was coding in Python. And I can also code Python in my notebooks via VSCode. But it seems weird that I can't code Matlab in notebooks via VSCode. Are there anything that I didn't notice which leads me to this error? Thanks a lot!
I had the same problem, and I tried several approaches.
Adding Matlab and Python kernel path into VSCode "settings.json" file -> didn't work.
Running VSCode with admin rights -> didn't work.
Running "jupyter notebook" and "activate jmatlab" (aka matlab_kernel) with the VSCode terminal -> didn't work.
So, there are two solutions.
Launch VSCode using Anaconda Navigator.
After selecting the jmatlab environment, select one of the two Matlab kernels and run the Matlab code.
Launch VSCode with the command line.
Open terminal (cmd).
Activate the jmatlab environment anywhere you want -> C:> activate jmatlab
Launch VSCode by simple typing -> (jmatlab)C:> code
Test your Matlab code.

Just installed Jupyter using Anaconda but can't run it using terminal. Says command not found

I just bought my very first Mac after using Windows my entire life and have been trying to install things. I am also still kind of a beginner at programming.
I installed Anaconda for Python 2.7 version, and then I installed the 3.7 version right after.
I tried going to terminal and typing jupyter notebook but it says:
zsh: command not found: jupyter
I am able to launch a jupyter notebook (I think) when I search for jupyter notebook in spotlight and executing the top hit.
I've been reading a lot on forums about this issue and see a lot of people talking about PATH which I am not really sure about.
I've seen people also post their which python information and theirs seem very different from mine:
which python3
usr/bin/python3
which python
usr/bin/python
Any help would be appreciated! Still learning how to set up this Mac. Thank you.
You might want to refer to this link https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html
3.1.2. Change Jupyter Notebook startup folder (Mac OS)
To launch Jupyter Notebook App:
Click on spotlight, type terminal to open a terminal window.
Enter the startup folder by typing cd /some_folder_name.
Type jupyter notebook to launch the Jupyter Notebook App The notebook interface will appear in a new browser window or tab.
From what I can understand you are not changing to the startup directory of Jupyter.
You need to add jupyter to your path.
In your terminal, type in the following command:
export PATH="/PUT JUPYTER PATH HERE:$PATH"
Then try jupyter notebook
Reasoning: If installing using pip install --user, you must add the user-level bin directory to your PATH environment variable in order to launch jupyter lab

How to fix run issues in vscode for python scripts

I have been using vscode for only css and html and pycharm for python and lately I have switched to vscode also for my python scripts . I did all the necessary configurations and extensions installations I even installed code runner but so far I have not been able to properly run my python scripts without passing through the debug face when I click on the run button it still shows only the output from the previous run.
I believe you are trying to run the code like a Jupyter notebook. If you highlight code and press shift+enter it should turn on a python interpreter that runs the code in a new pane.

Categories