Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code not finding conda python interpreter & failing to open ipynb file #513

Closed
Tony-Boksic opened this issue Oct 21, 2020 · 10 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@Tony-Boksic
Copy link

Bug: VS Code not finding conda python interpreter & failing to open ipynb file

Steps to cause the bug to occur

  1. Open ipynb file in a jupyter notebook in VS Code. The corrupted ipynb file is attached below.

Actual behavior

The ipynb file fails to open and returns the following error message:

Command failed: C:/Users/Tony/anaconda3/Scripts/activate && conda activate base && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\Users\Tony.vscode\extensions\ms-python.python-2020.9.112786\pythonFiles\pyvsc-run-isolated.py c:/Users/Tony/.vscode/extensions/ms-python.python-2020.9.112786/pythonFiles/printEnvVariables.py

Source: Python(Extension)

VS Code fails to find the conda python interpreter and the kernel is not found.

From the Developer Tools Console Output below, it looks like the corrupted file is pointing to the MYSQL Workbench python interpreter.

Expected behavior

I can no longer open the attached ipynb file in a VS-Code jupyter notebook. I have a problem with this one particular file as my other files open without a problem. I think that the problem comes from an error in the metadata as the metadata in this file looks very different to the metadata structure of the other files that successfully open.

This file used to open without any glitch in the past but now when I try to open the file, I see the above error.

I have pasted below the metadata information from a ipynb that opens successfully. The corrupted file used to open just like all my other files but recently it has produced this bug and I'm wondering how I can alter the metadata of the corrupted file in order to successfully open the file in a VS Code jupyter notebook.

Jupyter and/or Python environment

  • Jupyter server running: Local
  • Extension version: 2020.9.114305
  • VS Code version: 1.50.1
  • Setting python.jediEnabled: false
  • Setting python.languageServer: Microsoft
  • Python and/or Anaconda version: Python 3.8.3 64-bit ('base': conda)
  • OS: Windows
  • Virtual environment: conda

##Developer Tools Console Output

notificationsAlerts.ts:40

Command failed: C:/Users/Tony/anaconda3/Scripts/activate && conda activate base && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\Users\Tony.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\pyvsc-run-isolated.py c:/Users/Tony/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/printEnvVariables.py
onDidChangeNotification @ notificationsAlerts.ts:25

DevTools failed to load SourceMap: Could not load content for file:///C:/Users/Tony/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/semver-umd.js.map:

DevTools failed to load SourceMap: Could not load content for file:///C:/Users/Tony/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/tas-client-umd.js.map:

DevTools failed to load SourceMap: Could not load content for file:///C:/Users/Tony/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/main.js.map:

Corrupted IPYNB file
Corrupted_file.txt

Metadata of IPYNB file that opens successfully in VS Code

"metadata": {
"kernelspec": {
"display_name": "Python 3.8.3 64-bit ('base': conda)",
"language": "python",
"name": "python_defaultSpec_1597947257101"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3-final"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}

@rchiodo
Copy link
Contributor

rchiodo commented Oct 21, 2020

Thanks for the bug.

Does it work if you delete the metadata from the notebook? The notebook opens fine for me. I'm guessing the conda environment referenced in the notebook is either corrupt or no longer available on your machine.

@bantucaravan
Copy link

bantucaravan commented Oct 22, 2020

Hi had what appears to be a similar issue.

When I tried to run "Python: Create Python Interactive Window" in the command palette using a the python interpreter from a conda virtual environment I got this error message

Command failed: . activate "/Users/noah.chasek-macfoy@ibm.com/Desktop/projects/Lowes Deploy/bitbucket GIT REPO/conda_env" && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /Users/noah.chasek-macfoy@ibm.com/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/pyvsc-run-isolated.py /Users/noah.chasek-macfoy@ibm.com/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/printEnvVariables.py bash: activate: No such file or directory

The conda env I am using was created with the --prefix argument and so doesn't have a name, I wonder if that is the problem?

I am running VS code on Mac OS 10.14.6 (screen shot of error attached)

Do you think this is the same problem or a different one?

Screen Shot 2020-10-21 at 11 12 10 PM

UPDATE
note quite sure why, but removing the spaces from the interpreter path and restarting vscode got rid of the problem.

@greazer
Copy link
Member

greazer commented Oct 22, 2020

@Tony-Boksic, can you try deleting the metadata per Rich's comment above? We think this will resolve the issue. Thanks for the feedback!

@greazer greazer closed this as completed Oct 22, 2020
@Tony-Boksic
Copy link
Author

Thanks to both Rich and Greazer for your help. Deleting the metadata has resolved the issue. cheers!

Here is the metadata from the corrupted file that I deleted.

"metadata": {
"colab": {
"name": "numpy_random.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},

@Tony-Boksic
Copy link
Author

@rchiodo @greazer

Hi again, many thanks for your help on this issue previously. The solution that you provided worked(for a while). Once, I deleted the metadata, the ipynb file opened just fine in VS Code.

However, now I can now longer open the ipynb file. I get the same error as before:

Command failed: C:/Users/Tony/anaconda3/Scripts/activate && conda activate base && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\Users\Tony.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\pyvsc-run-isolated.py c:/Users/Tony/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/printEnvVariables.py

I have tried with the 2020.10 version of the python extension in VS Code but I get the same error.

Here is the ipynb file without the metadata
File_without_Metadata.txt

Might there be a way of modifying the JSON file so as to open the file in VS Code?

Many thanks for your help, Tony

@rchiodo
Copy link
Contributor

rchiodo commented Nov 11, 2020

If this command is failing:

Command failed: C:/Users/Tony/anaconda3/Scripts/activate && conda activate base && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\Users\Tony.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\pyvsc-run-isolated.py c:/Users/Tony/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/printEnvVariables.py

It's likely the notebook is specifying a kernel that doesn't exist or can't run on your machine. The root cause is not really the notebook being wrong, but that there's a kernel on your machine that isn't runnable.

You can check them all by using jupyter kernelspec list

@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 11, 2020
@DonJayamanne DonJayamanne added the bug Issue identified by VS Code Team member as probable bug label Nov 11, 2020
@Tony-Boksic
Copy link
Author

Tony-Boksic commented Nov 12, 2020

@rchiodo

Hi Rich,

Thanks for getting back. I've got just the one Kernel available:

C:\Users\Tony\anaconda3\share\jupyter\kernels\python3

As I have deleted the metadata from the ipynb file, it doesn't seem like the notebook is pointing to any specific kernel.

Do I need to specify the above kernel in the JSON file?

@rchiodo
Copy link
Contributor

rchiodo commented Nov 12, 2020

Sorry I may have misunderstood. I thought it wasn't working with the metadata in the notebook? Or is the metadata not in the notebook?

If it's the latter, you may have a problem with the 'jupyter interpreter' being set to a non existent interpreter. You can verify this by picking the 'Select interpreter to start jupyter server'.

If that fixes it, I should reopen this bug and change it to be about us using a non existent interpreter.

@Tony-Boksic
Copy link
Author

@rchiodo

Hi Rich,

Thanks for taking the time to help. That has fixed it. You're correct that the jupyter interpreter was incorrectly set.

I understand that it is confusing so I'll recap what has happened.

  • I originally had a corrupted ipynb file that no longer opened in VS Code as it was pointing to a non-existant python interpreter.
  • You provided a solution that involved deleting the metadata from this same ipynb file in order to open the file in VS Code.
  • This solution worked for a while. Once the metadata was deleted, the ipynb file opened successfully.
  • However, that same ipynb file stopped working and no longer opened. It is the same ipynb file with the metadata removed.
  • When I tried to open the file, it produced this error:

Command failed: C:/Users/Tony/anaconda3/Scripts/activate && conda activate base && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\Users\Tony.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\pyvsc-run-isolated.py c:/Users/Tony/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/printEnvVariables.py

As Rich indicated, by selecting the correct jupyter interpreter, this resolved the issue.

cheers, Tony

@rchiodo
Copy link
Contributor

rchiodo commented Nov 13, 2020

Thanks Tony.

I think I'm going to open another issue that makes sure we verify the jupyter intepreter before attempting to use it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

5 participants