Can't Run Jupyter Notebook In Vscode - Vanilla Python, Windows 10
Solution 1:
If you are having similar issues, please try the above steps mentioned in the question.
After reading this article I realised that I had to map the scripts installed with pip as well, even if it is in my roaming directory. https://discuss.python.org/t/windows-appdata-roaming-vs-local/2682. A confusion that costed me so many hours.
Here are the steps to add the variable:
- Go to environmental variables (if you don't know how, here is some instructions: https://www.techjunkie.com/environment-variables-windows-10/)
- In the "User variables for [username]" section, Edit "PATH" variable. (it can't be System variables section because only you will have access to your own roaming folder)
- Add "C:\Users[username]\AppData\Roaming\Python\Python38\Scripts" (or where the pip installs the scripts to to the PATH variable.
Finally restart VSCode for the new environmental variable to be updated for VSCode. Now run the scripts in the ipynb file and it should work. It may also complain that it needs other modules, in which case you can use 'pip' to install it.
NB: if you are not constrained by having an existing python version on your computer and not wanting to install more, you can also use the Python Anaconda Distribution. https://www.anaconda.com/distribution/
NB: if you want jupyter note to work for all users using your computer, you need to configure pip to download installs to a directory that is not in your "C:\Users[username]" folder, and add a System variable to it.
Solution 2:
For me, another solution helped. I'm not quite sure, what was the issue though, but somehow the state stored for the exact workspace made Python extension crash.
VSCode stores the states for all the workspaces, in its global config folder under /Code/User/workspaceStorage/
. See the path to the settings.json
in this help paragraph for your OS and then just replace the end of the path. For Windows, for example, the settings path is %APPDATA%\Code\User\settings.json
, so the state storage is
%APPDATA%/Code/User/workspaceStorage/
In this directory, there are many subdirectories with some hex names, which are hard to relate to the workspaces. To find out the id of the workspace
- Open it in VSCode
- Help → Toggle Developer Tools
- In Console tab there execute the following to get the workspace id:
vscode.context.configuration()["workspace"]["id"]
Then you can delete the workspaceStorage subfolder by the id of the workspaces.
Another approach is by using the workspaceStorage folder contents themselves. Each of this folder contains a workspace.json which usually includes the path to the workspace. So I wrote a little python script to help me browse them. At the end of the script, there is a draft on removing all the workspaces for the remote containers. Feel free to modify it according to your needs.
from glob import glob
import os, json, sys
from shutil import rmtree
if sys.platform.startswith("win32"): path = os.environ["APPDATA"] + '/Code/User/workspaceStorage/'# Windowselif sys.platform.startswith("darwin"): path = os.environ["HOME"] + '/Library/Application Support/Code/User/workspaceStorage/'# Mac OSelif sys.platform.startswith("linux"): path = os.environ["HOME"] + '/.config/Code/User/workspaceStorage/'# Linuxfor f in glob(path + "*/*.json"):
withopen(f) as fr:
ws = json.load(fr)
d = ""if"folder"in ws.keys():
d = ws["folder"]
elif"workspace"in ws.keys():
d = ws["workspace"]
elif"configuration"in ws.keys():
d = ws["configuration"]["fsPath"]
ws_path = os.path.dirname(f)
print(d, ws_path)
if d.startswith("vscode-remote://attached-container") or d.startswith("vscode-remote://dev-container"):
print("Inside a container")
# rmtree(ws_path)
Post a Comment for "Can't Run Jupyter Notebook In Vscode - Vanilla Python, Windows 10"