Python kernel automatically changes back to base in VS Code - python

I am trying to connect to a different environment for jupyter notebook in VS Code. I have settings.json as in the following:
"python.defaultInterpreterPath": "C:\\Users\\username\\.conda\\envs\\analytics\\python.exe"
I have manually added python path in select python interpreter
I have tried almost every solution, but I am unable to change kernel. Whenever I Reload Window it selects the intended kernel for a few seconds and then it changes back to base. I have never encountered this problem before, I have just installed anaconda and VS Code on this system. Can someone help me with this problem?

Related

Jupyter Running Wrong Cell in VSCode

I'm using the Jupyter extension on VSCode, Windows 10. I'm using Python through Anaconda.
I'm using a jupyter notebook and am running several different cells. After I run some of the cells a few times and restart the kernel a few times (to allow modules that I edited to update for the notebook), the notebook eventually stops running the correct cell. No matter what cell I try to run, it always runs the same cell, which is directly below my most used cell/the cell I used last. Opening and closing VSCode works but is only a temporary solution, and the issue has been arising more often. Does anyone know how to fix this?

Plotting in VS Code-Server (Python)

I setup a Visiual Studio Code-Sever on a Raspbarry Pi. I access the server via Safari from my Ipad. I can run scripts but I can not output plots. It is obvious that plt.show() does not work so I tried jupyter, but the interactive window remains black after I run the cell. There is no error to report but vs code is trying to install jupyter once again, although it is installed in my virtual environment. Similar problems occur when I try to start the output pane of neuron (it is not showing up at all).
Does anyone have ideas or ever had similar errors? It seems that jupyter cannot be accessed correctly.
Best regards!

Jupyter Notebook Kernel Crashing in VSCODE

I am interested in using VSCode's Jupyter notebook functionality and I am just trying to get to grips with it. I can start the kernel and run the notebook cells in VSCode.
After running particular cells it seems to crash with no warning and the code fails as the variables have been cleared. I have to reselect the kernel in the top right and start running the code again from the beginning until I get to the problem cells, and then the issue repeats itself.
I don't think it's anything to do with the Python code, it's some simple dataframe manipulation. I have tried the same notebook just running it in the browser and it works fine.I am running Jupyter through a venv with Python 3.7.6, MacOS Catalina (10.15.4), VSCode 1.45.1.
Something I noticed that might help indicate what is happening, is when it crashes I can run basic python statements in the notebook cells (without reselecting the kernel). But when I run my cell which tries to import tests from a .py file in the same folder or import data files using a relative path, it can't find them until I reselect the kernel. It seems like the cwd has changed? Can anyone assist with this?

How to switch environments for open jupyter notebook

If open a python jyputer notebook in vscode, then try to execute the notebook (so a kernel starts) and realize I need to activate a different environment, there doesn't seem to be a way to switch environments without completely quitting VSCode and coming back in.
If can switch environments in the terminal window or using the environment picker in the lower left, but it there doesn't seem to be a way to quit the current kernel and have it re-launch under the new environment. I've tried using the "Restart Kernel", closing the notebook and re-opening.
Is there a way to do this?
I'm a developer on this extension. The intention was for this feature to function as the Python Interactive Window did, where you could use the VSCode Interpreter picker to change out an open notebook to a new kernel. However it appears that we have a hitch that we shipped with this functionality. There is already an issue open in our github here which I believe that you filed (just going on user name match :)):
https://github.com/microsoft/vscode-python/issues/7862
That will be the right place to track our progress on fixing this, and it's on our immediate backlog.

How to show python environment objects in a pane in VSCode?

In R Studio, Matlab, and in some Python IDEs (like Thonny) you can see a list of the variables in your environment, together with some summary information like values, type etc.
Is there a way to do this in VSCode without going into debugging mode?
Seems like the closest as it gets to the RStudio Environment window is by installing Jupyter. Then you can type #%% in your .py file and a small "Run Cell" button will appear. Running the cell will open the "Python Interactive Window". There you can click the "See Variables Active" button to open up the Variable Window and see your variables... still a bit painful in comparison with RStudio, this should be integrated in VScode's IDE.
See steps here:
https://code.visualstudio.com/docs/python/jupyter-support-py#_variable-explorer-and-data-viewer
VS Code has an IPython mode with a dropdown box called Variables that basically does exactly this.
To enter IPython mode all you need to do is highlight a piece of code and hit Shift+Enter
The first time you do it there might be a bit of setting up to do but it was pretty easy to get it working on my Mac. Not sure what it's like on Windows/Linux though
Note: When I use VS Code I open it from the terminal (simply enter the command 'code') after I've activated my conda environment. That way the IPython interpreter uses my preferred conda environment when it launches.

Categories