-
Notifications
You must be signed in to change notification settings - Fork 277
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
Wrong kernel name in metadata kernelspec when using kernel from virtualenv #8796
Comments
Thanks for the bug. This is a side effect of how we start kernels. We don't use the kernelspec you wrote to disk. If there's a virtual environment, we just start the kernel directly ourselves. Which means we never 'find' the name 'venv_2' as the name of the kernel. Meaning it won't work if you open the same notebook in Jupyter. |
@rchiodo that's right, it doesn't work if I open the notebook in the Jupyter. Are you going to fix this? I'm asking because I've created a framework for converting Jupyter notebooks into web apps by adding YAML header. The framework is open-source https://github.com/mljar/mercury I would like to add an extension to VS Code - to be able to watch the app development in Jupyter & Mercury. |
This depends upon a lot of things. How many people hit this issue, How often we think people create kernelspecs for venvs vs just installing jupyter in them and running them directly. How hard it would be to fix this. This is the first complaint of this issue (and it's existed for the last two years) so my honest guess is no this won't be high priority. I don't think it would be that hard to fix though. It's merely changing the 'name' associated with our internal representation of a kernel. We could look to see if there's a kernelspec that matches a virtual environment and if so, use that as the name instead of our default. |
If you have the time to fix it, we certainly accept PRs as well. The logic is rather messy, but it's probably somewhere here: Line 391 in cae887e
We're eliminating duplicates (the venv_2 kernelspec was likely marked as a dupe). In that dupe eliminating code, the kernelspec name might be saved to be used later. |
@rchiodo do you think that it will be enough to replace following line vscode-jupyter/src/client/datascience/kernel-launcher/localKernelSpecFinderBase.ts Line 202 in cae887e
with kernelSpec.name = kernelJson?.name || kernelJson?.display_name || path.basename(path.dirname(specPath)); With this line the code will try to replace the I cant find tests for |
Sorry but I don't think that will fix the problem. I think the problem is later when we remove duplicates. Tests for this are generally here: I don't believe we have a test for this case yet. |
@rchiodo it makes sense. But I just dont see how removing duplicates can change the Lines 436 to 457 in cae887e
Maybe there is some other place which change the |
The 'interpreter' based kernelspec takes precedence over the local kernel spec one. It uses the 'name' of the interpreter based kernelspec which defaults to python3 |
Somewhere in this function it is:
|
@rchiodo thank you, but I give up. Because of this bug, VS Code Jupyter notebooks cant be run on Jupyter Notebook and Jupyter Lab and with tools like nbconvert. Maybe there were not many requests to fix this because people dont understand what is the root cause. |
I did some more looking. This line here is eliminating your global kernel spec: Line 167 in c4a90aa
So it's not even considered (it matches an interpreter). Then this line here generates a kernel name: Line 289 in c4a90aa
I think I have a fix for it. Maybe. I keep getting dupes in the kernel picker. Not sure how yet. |
Ah figured out why there's a dupe. This is more complicated than thought. We have restrictions on interpreters have to load super fast (especially the current one) and there's no way to get the matching kernelspec at that point. So it creates one based on the 'active' interpreter, but then it also creates one later that is slightly different (because it has the kernelspec on disk) |
Here's the partial working branch. I think we could either:
|
Another alternative, just let these kernelspecs through even if they don't have a custom environment. |
agreed. do this for all non default kernelspecs (excluse this way all custom (user created) kernelspecs are displayed. |
i think we already hide default kernel specs , all wed need to do is remove the code that looks for duplicate kernel specs based on interpreter. which i believe is a simple block of code |
If the user is using a named kernelspec for a notebook on the machine, then we shouldn't hide it or fail to write it to metadata. |
This should now be fixed in the pre-release version. Closing as this has been resolved as part of this issue #8481 @pplonski If the new pre-release version doesn't fix this please do let us know and we'll be happy to reopen this issue. |
@rchiodo @DonJayamanne @greazer thank you for looking into this. I've installed pre-release version:
The end of ... the rest of the file ...
"metadata": {
"interpreter": {
"hash": "5803cc62ceeeb9687df5d554a2392a6d093e68555e7672edae03c11d23d523ae"
},
"kernelspec": {
"display_name": "Python 3.8.10 ('dashenv': venv)",
"language": "python",
"name": "python3"
},
"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.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
} The
... the rest of the file ...
"metadata": {
"interpreter": {
"hash": "5803cc62ceeeb9687df5d554a2392a6d093e68555e7672edae03c11d23d523ae"
},
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "venv"
},
"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.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
The To summarize, it is partially working (for case 2). For the suggested kernel, it is not working. |
@pplonski
|
@DonJayamanne sorry for the confusion. I've started VS Code after machine restart and looks like it is working! Thank you very much! Closing the issue. |
No apologies necessary, glad that you were able to verify this and get back to us. |
Environment data
Expected behaviour
I created a new virtual environment with the name
venv_2
.I add kernel to that venv:
I created a new ipynb file in the VS Code and select kernel to venv_2 in the top right corner.
When I check the file of the notebook in the text editor I see the wrong
kernelspec
inmetadata
, it hasname
set topython3
but it should be set tovenv_2
.The contents of the notebook:
It should be
The text was updated successfully, but these errors were encountered: