I have an existing vanilla Python installed on my Windows 10 computer, and I do not want to reinstall Anaconda.
When trying to run code from an ipynb file in Visual Studio Code, I get the following error:
Error: Jupyter cannot be started. Error attempting to locate jupyter:
at A.startServer (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:786120)
at async A.ensureServerAndNotebookImpl (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:785575)
at async A.ensureServerAndNotebook (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:785376)
at async A.submitCode (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:782328)
at async A.reexecuteCell (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:75:879318)
Also with the following error from Visual Studio Code:
ⓘ Couldn't find kernel 'Python 3' that the notebook was created with. Re...
ⓧ Jupyter server crashed. Unable to connect. Error code from jupyter: 1
(screenshot)
Below are some of the things I have tried:
Check if the Visual Studio Code extension in correctly installed
"Jupyter" extension is deprecated. I had the "Python" plugin from Microsoft installed which contained Jupiter Notebook support.
Jupyter Installed Correctly
I tried reinstalling Jupyter:
python -m pip install --upgrade pip
pip install jupyter
pip install notebook
Tried to run Jupyter in the terminal/command line
jupyter notebook // Didn't work
Output:
jupyter : The term 'jupyter' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ jupyter
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (jupyter:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
This gave an error not able to find Jupyter executable. According to this post, I tried the following and it worked: How can I fix "'jupyter' is not recognized as an internal or external command, operable program or batch file" when running Jupyter on Windows?
python -m notebook
Check if pointing to the right interpreter
As per Jupyter server: not started, no kernel in Visual Studio Code, I tried:
Press Command + Shift + P to open a new Command Palette
Type Python: Select interpreter to start Jupyter Notebook server
But I only had one version of Python installed on my computer, and doing this didn't make a difference.
Check the Path
There was this comment about PYTHONPATH on How can I use a Python script in the command line without cd-ing to its directory? Is it the PYTHONPATH?, but since the python directory is correctly referenced and python works from the command line, I did not investigate it further.
One thing to note is pip installs to my "C:/Users/[username]/appdata/Roaming/Python-38/" folder while my Python is installed in "C:\Program Files\Python38-32".
For me, another solution helped. I'm not quite sure what the issue was, but somehow the state stored for the exact workspace made the Python extension crash.
Visual Studio Code stores the states for all workspaces in its global configuration 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 hexadecimal names, which are hard to relate to the workspaces. To find out the id of the workspace
Open the workspace in Visual Studio Code
Help → Toggle Developer Tools
In the Console tab, 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 workspace.
Another approach is by using the workspaceStorage folder contents themselves. Each of these folders contains a workspace.json file 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"): # Windows
path = os.environ["APPDATA"] + '/'
elif sys.platform.startswith("darwin"): # macOS
path = os.environ["HOME"] + '/Library/Application Support/'
elif sys.platform.startswith("linux"):
path = os.environ["HOME"] + '/.config/'
path += 'Code/User/workspaceStorage/'
print(path)
assert os.path.exists(path)
for ws_json in glob(path + "*/workspace.json"):
with open(ws_json) as file:
ws = json.load(file)
target = ""
if "folder" in ws.keys():
target = ws["folder"]
elif "workspace" in ws.keys():
target = ws["workspace"]
elif "configuration" in ws.keys():
target = ws["configuration"]["fsPath"]
ws_dir = os.path.dirname(ws_json)
ws_base = os.path.basename(ws_dir)
print(ws_base, target)
if (
target.startswith("vscode-remote://attached-container")
or target.startswith("vscode-remote://dev-container")):
print("Inside a container")
# rmtree(ws_dir)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With