Skip to content

Kernel specs with custom env variables not listed in list of kernel specs #7719

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

Closed
DonJayamanne opened this issue Sep 28, 2021 · 13 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@DonJayamanne
Copy link
Contributor

  • Assume you have a conda env abc
  • Create a kernel spec in the above conda env named xyz
    • This should be a kernel spec with custom env variables
    • This should be located in the env folder & not globally
  • We do not list this kernel spec
@DonJayamanne DonJayamanne added the bug Issue identified by VS Code Team member as probable bug label Sep 28, 2021
@greazer greazer added this to the October 2021 milestone Sep 30, 2021
@DonJayamanne DonJayamanne self-assigned this Sep 30, 2021
@DonJayamanne
Copy link
Contributor Author

@IanMatthewHuff weird it works for you, this doesn't work for me in stable or insiders.
This is the issue I was referring to today.

@IanMatthewHuff
Copy link
Member

@DonJayamanne Just took a look. In my setup I used a conda env to install kernelspecs globally not locally in the env folder. That was fixed for me a release or two ago, and has been ok since then.

@rchiodo
Copy link
Contributor

rchiodo commented Jan 25, 2022

This is working for me now.

@rchiodo rchiodo closed this as completed Jan 25, 2022
@IanMatthewHuff IanMatthewHuff added verified Verification succeeded and removed verified Verification succeeded labels Jan 28, 2022
@roblourens
Copy link
Member

Anything to verify here?

@roblourens
Copy link
Member

This should be a kernel spec with custom env variables

If this should be verified with the original steps, how do I do that?

@roblourens roblourens added the verification-steps-needed Steps to verify are needed for verification label Feb 1, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Feb 1, 2022

Kernelspecs normally look like so (you can find yours with jupyter kernelspec list --json):

{
      "spec": {
        "argv": [
          "python",
          "-m",
          "ipykernel_launcher",
          "-f",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "Python 3 (ipykernel)",
        "language": "python",
        "interrupt_mode": "signal",
        "metadata": {
          "debugger": true
        }
      }
    }

For one that matches a specific interpreter, the argv[0] would be the path to the interpreter:

{
      "spec": {
        "argv": [
          "c:\\users\\aku91\\miniconda3\\envs\\foobar\\python.exe",
          "-m",
          "ipykernel_launcher",
          "-f",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "MY CUSTOM FOOBAR",
        "language": "python",
        "interrupt_mode": "signal",
        "metadata": {
          "debugger": true
        }
      }
    }

That shouldn't show up though (at least not yet) as it doesn't have an 'env' entry. To add an 'env' entry, just do this:

{
      "spec": {
        "argv": [
          "c:\\users\\aku91\\miniconda3\\envs\\foobar\\python.exe",
          "-m",
          "ipykernel_launcher",
          "-f",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "MY CUSTOM FOOBAR",
        "language": "python",
        "interrupt_mode": "signal",
        "metadata": {
          "debugger": true
        }
       "env": {
            "FOOBAR": 1
       }
      }
    }

@rzhao271 rzhao271 added verified Verification succeeded and removed verified Verification succeeded labels Feb 1, 2022
@roblourens
Copy link
Member

Sorry, where do I put this JSON?

@rchiodo
Copy link
Contributor

rchiodo commented Feb 2, 2022

If you type jupyter kernelspec list it will show where your other kernels are. Mine are here:

Available kernels:
  .net-csharp                                                                               C:\Users\aku91\AppData\Roaming\jupyter\kernels\.net-csharp
  .net-fsharp                                                                               C:\Users\aku91\AppData\Roaming\jupyter\kernels\.net-fsharp
  .net-powershell                                                                           C:\Users\aku91\AppData\Roaming\jupyter\kernels\.net-powershell
  .venvkernel                                                                               C:\Users\aku91\AppData\Roaming\jupyter\kernels\.venvkernel
  .venvnokernel                                                                             C:\Users\aku91\AppData\Roaming\jupyter\kernels\.venvnokernel
  dupeenvdos                                                                                C:\Users\aku91\AppData\Roaming\jupyter\kernels\dupeenvdos
  dupeenvuno                                                                                C:\Users\aku91\AppData\Roaming\jupyter\kernels\dupeenvuno
  julia-1.7                                                                                 C:\Users\aku91\AppData\Roaming\jupyter\kernels\julia-1.7
  python3101jvsc74a57bd02303460301e1fef0aa1e694dd88ed9c989d4570ff871b238892fc427e0c167de    C:\Users\aku91\AppData\Roaming\jupyter\kernels\python3101jvsc74a57bd02303460301e1fef0aa1e694dd88ed9c989d4570ff871b238892fc427e0c167de
  special_venv_kernel                                                                       C:\Users\aku91\AppData\Roaming\jupyter\kernels\special_venv_kernel
  python3                                                                                   C:\Users\aku91\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\share\jupyter\kernels\python3

@roblourens
Copy link
Member

I added it to one of my existing kernelspecs, then I try to access the var like os.environ.get('FOO'), but it's empty. Should it be there or does it get exposed somewhere else?

@rchiodo
Copy link
Contributor

rchiodo commented Feb 2, 2022

One of your existing kernelspecs may not be using the kernelspec to launch the kernel. I guess it depends.

But yes that's how you'd test it with a custom kernelspec.

@roblourens
Copy link
Member

Why would that be? How do I find one that uses the kernelspec?

@rchiodo
Copy link
Contributor

rchiodo commented Feb 2, 2022

Here's my list:

image

You can see that I have a global python kernel and two other kernelspecs that map to the same interpreter. The two other ones are listed as jupyter kernels. That's where you'd start one that's a custom kernel.

It might be you edited a kernelspec that had the same name as an interpreter and so you started the interpreter instead of your custom kernelspec. You need to give it a unique name for it to show up as a different entry.

@greazer
Copy link
Member

greazer commented Feb 25, 2022

Verified

@greazer greazer added verified Verification succeeded and removed verification-steps-needed Steps to verify are needed for verification labels Feb 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2023
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 verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants