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

Adding proper activation for conda envs to ipykernel creation #417

Closed
wants to merge 1 commit into from
Closed

Adding proper activation for conda envs to ipykernel creation #417

wants to merge 1 commit into from

Conversation

ericdill
Copy link

@ericdill ericdill commented Jul 25, 2019

Discussion and details in #416

Closes #416

What are your general thoughts so far @blink1073? I could use some help thinking through how this should be tested.

TODO:

  • establish best way to test this. I'm definitely open to suggestions. My idea is to create a conda environment including ipykernel, create a kernel with this new code path and make sure that the kernel can start. That seems like a very slow test though, so... thoughts?
  • QA on windows. I'll be able to do soon.
  • this will require conda 4.6 as a minimum version. From a UX perspective, it would be a good idea to put some safeguards in place to ensure that the user's environment supports conda run by checking the conda version during kernel install.

Notes

  • This implementation assumes that the process that is launching your kernels knows how to handle the conda run command -- in other words the notebook / lab environment that is spawning kernels should have been installed with conda too.

@ericdill
Copy link
Author

Build failure is for 3.7-dev and seems unrelated

@blink1073
Copy link
Contributor

I think we should test the version of conda using LooseVersion and error out on the CLI. I think having a separate CI build for the conda envy testing is fair.

@blink1073
Copy link
Contributor

We could check the location of the “jupyter” executable using shutil.which and see if it matches the conda location.

@ericdill
Copy link
Author

Just tried this on windows and got the following error. I suspect that I need to handle conda differently.

[E 21:58:59.780 NotebookApp] Failed to run command:
    ['conda', 'run', '-n', 'envs', 'python', '-m', 'ipykernel_launcher', '-f', 'C:\\Users\\Eric\\AppData\\Roaming\\jupyter\\runtime\\kernel-66d6318b-d76e-4269-b036-0d26a4dfcb79.json']
        PATH='C:\\Users\\Eric\\AppData\\Local\\Continuum\\miniconda3\\envs\\ipykernel-dev;C:\\Users\\Eric\\AppData\\Local\\Continuum\\miniconda3\\envs\\ipykernel-dev\\Library\\mingw-w64\\bin;C:\\Users\\Eric\\AppData\\Local\\Continuum\\miniconda3\\envs\\ipykernel-dev\\Library\\usr\\bin;C:\\Users\\Eric\\AppData\\Local\\Continuum\\miniconda3\\envs\\ipykernel-dev\\Library\\bin;C:\\Users\\Eric\\AppData\\Local\\Continuum\\miniconda3\\envs\\ipykernel-dev\\Scripts;C:\\Users\\Eric\\AppData\\Local\\Continuum\\miniconda3\\envs\\ipykernel-dev\\bin;C:\\Users\\Eric\\AppData\\Local\\Continuum\\miniconda3\\condabin;C:\\windows\\system32;C:\\windows;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0;C:\\windows\\System32\\OpenSSH;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Users\\Eric\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\Eric\\AppData\\Local\\inkdrop\\bin;C:\\Users\\Eric\\AppData\\Local\\GitHubDesktop\\bin'
        with kwargs:
    {'stdin': -1, 'stdout': None, 'stderr': None, 'cwd': 'C:\\Users\\Eric\\Documents\\GitHub\\ipykernel', 'close_fds': False}

[E 21:58:59.780 NotebookApp] Uncaught exception POST /api/sessions (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/api/sessions', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\tornado\web.py", line 1699, in _execute
        result = await result
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\notebook\services\sessions\handlers.py", line 72, in post
        type=mtype))
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 88, in create_session
        kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 101, in start_kernel_for_session
        self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\tornado\gen.py", line 209, in wrapper
        yielded = next(result)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 168, in start_kernel
        super(MappingKernelManager, self).start_kernel(**kwargs)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
        km.start_kernel(**kwargs)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\jupyter_client\manager.py", line 259, in start_kernel
        **kw)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\jupyter_client\manager.py", line 204, in _launch_kernel
        return launch_kernel(kernel_cmd, **kw)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\site-packages\jupyter_client\launcher.py", line 138, in launch_kernel
        proc = Popen(cmd, **kwargs)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\subprocess.py", line 800, in __init__
        restore_signals, start_new_session)
      File "C:\Users\Eric\AppData\Local\Continuum\miniconda3\envs\ipykernel-dev\lib\subprocess.py", line 1207, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] The system cannot find the file specified
[W 21:58:59.845 NotebookApp] Unhandled error
[E 21:58:59.846 NotebookApp] {
      "Host": "localhost:8888",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0",
      "Accept": "application/json, text/javascript, */*; q=0.01",
      "Accept-Language": "en-US,en;q=0.5",
      "Accept-Encoding": "gzip, deflate",
      "Content-Type": "application/json",
      "X-Xsrftoken": "2|3cf61930|d5bec6b8e0aaf72a225eb2598c5de8b7|1574650588",
      "X-Requested-With": "XMLHttpRequest",
      "Content-Length": "97",
      "Origin": "http://localhost:8888",
      "Dnt": "1",
      "Connection": "keep-alive",
      "Referer": "http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=ipykernel-dev",
      "Cookie": "username-localhost-8888=\"2|1:0|10:1574650732|23:username-localhost-8888|44:NTc1MjYwODdhODQzNDI2MGEyOTJiMDA4MzEyOGVlN2Y=|f97b0b88fcfdf9c7fc1828ed71ca9f448699db636505d66df40a8c25693024e3\"; _xsrf=2|3cf61930|d5bec6b8e0aaf72a225eb2598c5de8b7|1574650588"
    }
[E 21:58:59.846 NotebookApp] 500 POST /api/sessions (127.0.0.1) 151.14ms referer=http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=ipykernel-dev
[I 21:59:09.092 NotebookApp] Saving file at /Untitled.ipynb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding support for activating conda environments in the kernel.json launch script?
2 participants