3

I use ubuntu (through Windows Subsystem For Linux) and I created a new conda environment, I activated it and I installed a library in it (opencv). However, I couldn't import opencv in Jupyter lab till I created a new kernel that it uses the path of my new conda environment. So, my questions are:

  1. Do I need to create a new kernel every time I create a new conda environment in order for it to work? I read that in general we should use kernels for using different versions of python, but if this is the case, then how can I use a specific conda environment in jupyter lab? Note that browsing from Jupyter lab to my new env folder or using os.chdir to set up the directory didn't work.

  2. Using the new kernel that it's connected to the path of my new environment, I couldn't import matplotlib and I had to activate the new env and install there again the matplotlib. However, matplotlib could be imported when I was using the default kernel Python3. Is it possible to have some standard libraries to use them with all my conda environments (i.e. install some libraries out of my conda environments, like matplotlib and use them in all my enviroments) and then have specific libraries in each of my environments? I have installed some libraries through the base environment in ubuntu but I can't import these in my new conda environment.

Thanks in advance!

Katerina
  • 31
  • 3

2 Answers2

2

To my best understanding: You need ipykernel in each of the environments so that jupyter can import the other library. In my case, I have a new environment called TensorFlow, then I activate it and install the ipykernel, and then add it to jupyter kernelspec. Finally I can access it in jupyter no matter the environment is activated or not.

0
  1. For working with jupyter notebook, you need to install ipykernel inorder to activate that particular environment in the jupyter notebook. Once the ipykernel library is installed, you can take the change kernel opion from kernel menu as shown in the attached screenshot.You don't need to browse to new wnv folder or set directory.

enter image description here

  1. You can install the new packages in the new environment from jupyter notebook itself with an "!" in the front as below: enter image description here

  2. We can access the pip packages in the base environment in the newly created environment as well. You can check the same with "pip freeze" command

Conda commands to create an environment and install ipykernel in it:

conda create -n <env_name> -c <channel> python=python_version

Eg: conda create -n env_stack -c intel python=3.6

source activate <env_name>
conda install ipykernel
ipython kernel install --name <env_name> --user 
Lakshmi - Intel
  • 581
  • 3
  • 10
  • 1
    So, as I understand: 1. Each environment needs to have an ipykernel? Can we have many environments under an ipykernel? 2-3. The only way to have some libraries for all my environments is to install them in the base environment with pip? Would this work with conda? Thanks! – Katerina Dec 10 '19 at 09:53
  • 1
    If you want to work in jupyter notebook, inorder to access the conda environment you need to install ipykernel seperately in each conda environments. – Lakshmi - Intel Dec 10 '19 at 14:37