Python Forum
Jupyter notebooks, jupyter kernels, virtual environment created in Anaconda...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jupyter notebooks, jupyter kernels, virtual environment created in Anaconda...
#1
Hello Forum,

I think I am clear on what a virtual environment is: it is a "folder" that contains specific Python libraries/modules and a specific Python interpreter (we can choose the version).
  • Every environment has its own Python interpreter. The purpose of virtual environments is to keep projects and their dependencies separate so there are no conflicts.
  • Virtual environments, once created, are generally stored all together in a specific and regular folder on our computer. The folder can be anywhere. And the Python scripts that use a specific and activated environment should not be saved inside the environment itself (even if they can be) but in some other folder.
  • I am using Anaconda and the Anaconda Navigator to create virtual environments at the Anaconda terminal: I start in the (base) virtual environment and then use conda to create a new environment, (ven1):

    (base) C:\Users\Tom\python_env\ conda create --name ven1 # to create a new environment called ven1
    (base) C:\Users\Tom\python_env\ conda activate ven1 # to activate the environment ven1
    (ven1) C:\Users\Tom\python_env\ jupyter notebook # this launches jupyter notebook from (ven1). The notebook should use the Python interpreter associated with environment (ven1)? But it doesn't!

  • When I launch jupyter notebook from (ven1), the jupyter kernel for the notebook is the SAME as the kernel that would be used if I launched the Jupyter notebook from the (base) environment. Why? I expected the kernel to be automatically different since (base) and (ven1) have different Python interpreters.
  • A jupyter kernel is a different name for Python interpreter, correct? So when I launch Jupyter from different environments, shouldn't we there be different kernels since we are using a Jupyter notebook from two different virtual environments having different Python interpreters?
  • To avoid the problem, we have to run this code to install a new kernel in (ven1)...but doesn't (ven1) already have its own kernel which is different from the kernel of (base)?


    (ven1) C:\Users\Brett\python_env\ conda install ipykernel # we install the package ipykernel inside the ven1 environment
    (ven1) C:\Users\Brett\python_env\ ipython kernel install --user --name=ven1kernel # creates a new kernel
    (ven1) (C:\Users\Brett\python_env\ jupyter kernelspec list #lists all jupyter kernels


In essence, does this all mean that, even if we create a new virtual environment and launch jupyter notebook from it, the kernel that is used, by default, is the kernel (Python interpreter) associated with the (base) environment! This is a problem in the notebook. To avoid that, we need to create a new jupyter kernel and select that kernel in the notebook to be able to use the modules/libraries contained inside the activated environment (ven1). This sounds redundant since (ven1) already has its own Python interpreter but are creating a new one using the library ipykernel

Thank you!
Reply


Messages In This Thread
Jupyter notebooks, jupyter kernels, virtual environment created in Anaconda... - by bytecrunch - Sep-13-2023, 12:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Jupyter Notebook TypeError Holidays entity loader class bmanning20 0 2,776 Jul-20-2023, 06:52 PM
Last Post: bmanning20
  Why does graph look different in Codecademy and Jupyter Notebook abc123456 1 1,511 Mar-29-2023, 09:22 AM
Last Post: newbieAuggie2019
  Setting up and integrating Jupyter Notebook development environment with VSC Drone4four 3 1,958 Sep-12-2022, 09:18 AM
Last Post: Drone4four
  Jupyter:On my computer, where csv file is? Leloup 2 1,524 Mar-22-2022, 04:39 PM
Last Post: Leloup
Thumbs Up can't access data from URL in pandas/jupyter notebook aaanoushka 1 1,896 Feb-13-2022, 01:19 PM
Last Post: jefsummers
Exclamation Jupyter Notebook - Help Needed! eyadfr 1 1,877 Jan-26-2022, 06:42 PM
Last Post: jefsummers
  Help needed with Jupyter Notebook eyadfr 4 2,164 Jan-04-2022, 08:20 PM
Last Post: snippsat
  HELP! Importing json file into csv into jupyter notebook vilsef 2 2,612 Jan-22-2021, 11:06 AM
Last Post: snippsat
  How can draw a real-time marker on map using folium/leaflet Jupyter notebook C3PO 0 2,446 Dec-22-2020, 07:04 PM
Last Post: C3PO
  Python Custom Module not working in Jupyter Notebook with Pandas fid 0 2,060 Jul-04-2020, 11:05 AM
Last Post: fid

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020