Jupyter running under virtualenv is running "external" Python for notebook kernels

37 views
Skip to first unread message

Michael Bright

unread,
Sep 26, 2018, 2:44:15 AM9/26/18
to Project Jupyter

I generally use Anaconda Python as my distribution but wanted to use a separate (actually Cygwin) Python for running the kubernetes-client-python which is pip installable.
Basically my Jupyter (from my Cygwin/virtualenv) is picking up the Anaconda Python for Python3 kernels which is not what I was expecting.
On the other hand if I open a Terminal from Jupyter I have the correct Python/Kubernetes in my PATH.

The short question is what would you recommend I do using virtualenv as described - or maybe you'd push me to use Anaconda/env/pip?

The longer question is what do you think is happening - see below.

Thx,

Here's what I tried.

Feeling more comfortable with virtualenv than "conda env" I installed virtualenv in my system (Cygwin) Python environment.

I activated my virtualenv, pip installing jupyter and kubernetes and verified the path to my jupyter command - it was the one in my virtualenv.

I started Jupyter, opened a notebook and was surprised that the Kubernetes module wasn't available (because it was using my Anaconda Python3 as the kernel).

I wondered if it was picking something up from ~/.local ~/.jupyter or ~/.ipython so I 
    sourced ~/.virtualenv/kubernetes/bin/activate

    created an empty directory ~/.virtualenv/kubernetes/HOME

    started Jupyter as
           HOME=~/.virtualenv/kubernetes/HOME jupyter
           (maybe I should set WINHOME or other, in any case .local, .jupyter, .ipython don't exist under my Windows home, only under Cygwin home)

I opened a notebook and still no Kubernetes available.

I opened a terminal and verified my PATH (to check virtualenv was active) and ran a Python script to verify Kubernetes was avaliable there.
I then ran a pstree -aps <jupyter-pid> and could see that my notebook was running under anaconda Python.




Message has been deleted

Michael Bright

unread,
Sep 26, 2018, 6:17:12 AM9/26/18
to Project Jupyter

OK, the answer to my first question would be to use conda-forge, didn't realize the kubernetes client was available there, so:
    
conda install -c conda-forge python-kubernetes
did the trick.

I'm still interested to understand why my virtualenv/cygwin/jupyter was picking up my Anaconda Python3 kernel though - pour mourir moins bete as they say around here.

Roland Weber

unread,
Oct 8, 2018, 4:00:02 AM10/8/18
to Project Jupyter
I'm still interested to understand why my virtualenv/cygwin/jupyter was picking up my Anaconda Python3 kernel though - pour mourir moins bete as they say around here.

If I read correctly, you started Jupyter with a plain 'jupyter' command, no absolute path. Have you check the PATH environment variable to see where that command is actually found? You might have started the Anaconda jupyter instead of the cygwin jupyter.

cheers,
  Roland
Reply all
Reply to author
Forward
0 new messages