{"id":29301,"date":"2023-01-30T13:38:46","date_gmt":"2023-01-30T13:38:46","guid":{"rendered":"https:\/\/www.process.st\/templates\/how-to-setup-a-jupyter-notebook-in-vs-code-virtual-env-kernels\/"},"modified":"2024-06-18T13:39:48","modified_gmt":"2024-06-18T13:39:48","slug":"how-to-setup-a-jupyter-notebook-in-vs-code-virtual-env-kernels","status":"publish","type":"post","link":"https:\/\/www.process.st\/templates\/how-to-setup-a-jupyter-notebook-in-vs-code-virtual-env-kernels\/","title":{"rendered":"How To Setup a Jupyter Notebook in VS Code (Virtual Env + Kernels)"},"content":{"rendered":"<section id=\"overview\">\n<h2>\u200d Overview<\/h2>\n<div class=\"text-content\">\n<h3><strong>HOW TO SETUP JUPYTER NOTEBOOK IN VS CODE (W\/ VIRTUAL ENV &amp; KERNELS)<\/strong><\/h3>\n<\/p><\/div>\n<div class=\"text-content\">\n<p>Figuring out how to how setup a&nbsp;<code>jupyter notebook<\/code>&nbsp;is pretty easy \u2013 you just open your terminal, install jupyter &amp; run&nbsp;<code>jupyter notebook<\/code>.<\/p>\n<p>But figuring out how to do it inside of VS CODE was not very intuitive (at least not for me, as I am kind of a newb with python).<\/p>\n<p>But learning from newbies is the best thing you can do because, as you will find out, we are so \u201cdumb\u201d that our processes need to be so detailed that a monkey could run them, so it\u2019s unlikely we will leave out some critical step that just ruins your whole day.<\/p>\n<p>So here is my process, compiled from digging, reading, and banging my head against a wall until i nailed it.<\/p>\n<p>Let\u2019s get to it.<\/p>\n<\/p><\/div>\n<div class=\"text-content\">\n<hr>\n<\/p><\/div>\n<div class=\"text-content\">\n<h4><strong>Prerequisites<\/strong><\/h4>\n<h5><strong>Install jupyter<\/strong><\/h5>\n<p>First, you obviously need jupyter installed.<\/p>\n<p>If you haven\u2019t done that, then do that first.<\/p>\n<p>Not going to cover that here because i don\u2019t know what system you\u2019re on, or package manager you use.<\/p>\n<p>Onwards.<\/p>\n<h5><strong>VS Code jupyter extensions<\/strong><\/h5>\n<p>i don\u2019t know enough about extensions to recommend \u201cthe perfect setup\u201d, but here\u2019s what I have installed.<\/p>\n<p>so if you feel like just being a lemming and following my lead, here ya go:<\/p>\n<ol>\n<li>Jupyter (extension ID:&nbsp;<code>ms-toolsai.jupyter<\/code>)<\/li>\n<li>Jupyter Notebook Renderers (extension ID:&nbsp;<code>ms-toolsai.jupyter-renderers<\/code>)<\/li>\n<li>Jupyter Keymap (extension ID:&nbsp;<code>ms-toolsai.jupyter-keymap<\/code>)<\/li>\n<li>VS Code Jupyter Notebook Previewer (extension ID:&nbsp;<code>jithurjacob.nbpreviewer<\/code>)<\/li>\n<\/ol><\/div>\n<div class=\"text-content\">\n<h5><strong>Step 1. Create project folder<\/strong><\/h5>\n<p>First you need a project folder, so create that.<\/p>\n<p>You can use Finder, Terminal, or do it in VS Code.<\/p>\n<p>I like doing it without the GUI because \u201cpractice makes progress\u201d.<\/p>\n<p>Tweet that. You\u2019ll look clever &amp; sophisticated.<\/p>\n<p>And then get back to work because you aren\u2019t here to be dickin\u2019 around on social media.<\/p>\n<p>Create your project folder:<\/p>\n<pre># syntax\nmkdir &lt;folder name&gt;\n\n\n# example\nmkdir myproject<\/pre>\n<h5><strong>Step 2. Create, activate &amp; select your virtual environment<\/strong><\/h5>\n<p>Navigate to \/ open your project folder and create a virtual environment inside of it:<\/p>\n<pre># syntax\npython3 -m venv &lt;virtual environment name&gt;\n\n# example\n# that would create a virtual environment named 'myenv'\npython3 -m venv myenv<\/pre>\n<p>Now activate the virtual environment and when VS CODE prompts you to set it as default for the project, hit yes.<\/p>\n<pre># syntax\nsource &lt;virtual environment name&gt;\/bin\/activate\n\n# example\nsource myenv\/bin\/activate<\/pre>\n<h5><strong>Step 3. Install&nbsp;<code>ipykernel<\/code><\/strong><\/h5>\n<p>Now that your virtual environment is activated, install&nbsp;<code>ipykernel<\/code><\/p>\n<pre>pip3 install ipykernel<\/pre>\n<h5>Step 4. Create new kernel<\/h5>\n<p>Now you can create a new kernel to be used for your project:<\/p>\n<pre># syntax\npython3 -m ipykernel install --user --name=&lt;projectname&gt;\n\n\n# example\n# That would create a kernel named 'myproject'\npython3 -m ipykernel install --user --name=myproject<\/pre>\n<h5>Step 5. Start jupyter<\/h5>\n<p>Now you can start Jupyter. I do it from the VS Code terminal.<\/p>\n<pre>jupyter notebook<\/pre>\n<p>If you did this right you should see something like this in your terminal:<\/p>\n<pre>To access the notebook, open this file in a browser:\n        file:\/\/\/Users\/&lt;your username&gt;\/Library\/Jupyter\/runtime\/nbserver-15044-open.html\n    Or copy and paste one of these URLs:\n        https:\/\/localhost:8889\/?token=f1ae910e56381c26a62cfb18f83241076bd11d84f7e8e36e\n     or https:\/\/127.0.0.1:8889\/?token=f1ae910e56381c26a62cfb18f83241076bd11d84f7e8e36e<\/pre>\n<h5><strong>Step 6. Select kernel for project<\/strong><\/h5>\n<p>Now you can assign the kernel to the project in VS CODE.<\/p>\n<p><strong>Step 6.1: Create a new Jupyter notebook<\/strong><\/p>\n<ul>\n<li>Open the VSCODE search bar:&nbsp;<code>cmd+shift+p<\/code><\/li>\n<li>Type in &amp; choose: \u201cCreate: New Jupyter Notebook\u201d<\/li>\n<\/ul>\n<p><strong>Step 6.2: Choose your kernel<\/strong><\/p>\n<ul>\n<li>Open the VSCODE search bar:&nbsp;<code>cmd+shift+p<\/code><\/li>\n<li>Type in &amp; choose: \u201cNotebook: Select Notebook Kernel\u201d<\/li>\n<\/ul>\n<p>At the bottom of your VS Code window, you should see \u201cJupyter Server: Local\u201d<\/p>\n<\/p><\/div>\n<\/section>\n<section id=\"hey-there\">\n<h2> Hey there!<\/h2>\n<div class=\"text-content\">\n<h4><strong>hey there! <\/strong><strong> <\/strong><\/h4>\n<p>My name's Devin Schumacher.<\/p>\n<p>Im widely recognized as the World's Best SEO &amp; grumpy cat impersonator.<\/p>\n<p>I like making stuff easier, so I make these SOPs.<\/p>\n<p>Hope you enjoy!<\/p>\n<\/p><\/div>\n<div class=\"image-content\">\n<figure> <a href=\"https:\/\/www.process.st\/templates\/wp-content\/uploads\/2024\/02\/vs2QMSG48djt6A_fPbxDFg.jpg\" alt=\" Hey there!\" target=\"_blank\" rel=\"noopener\"> <img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.process.st\/templates\/wp-content\/uploads\/2024\/02\/vs2QMSG48djt6A_fPbxDFg.jpg\"> <\/a><br \/>\n  <\/figure>\n<\/p><\/div>\n<div class=\"text-content\">\n<h4><strong>Say hey  on social!<\/strong><\/h4>\n<p><strong>YouTube<\/strong>: <a href=\"https:\/\/www.youtube.com\/@devinschumacher?sub_confirmation=1\" rel=\"nofollow noopener\" target=\"_blank\">@devinschumacher<\/a><br \/><strong>Instagram<\/strong>: <a href=\"https:\/\/instagram.com\/dvnschmchr\" rel=\"nofollow noopener\" target=\"_blank\">@dvnschmchr<\/a><br \/><strong>Twitter<\/strong>: <a href=\"https:\/\/twitter.com\/dvnschmchr\" rel=\"nofollow noopener\" target=\"_blank\">@dvnschmchr<\/a><br \/><strong>Facebook<\/strong>: <a href=\"https:\/\/www.facebook.com\/dvnschmchr\" rel=\"nofollow noopener\" target=\"_blank\">@dvnschmchr<\/a><br \/><strong>Linkedin<\/strong>: <a href=\"https:\/\/www.linkedin.com\/in\/devinschumacher\" rel=\"nofollow noopener\" target=\"_blank\">@devinschumacher<\/a><br \/><strong>Tiktok<\/strong>: <a href=\"https:\/\/www.tiktok.com\/@dvnschmchr\" rel=\"nofollow noopener\" target=\"_blank\">@dvnschmchr<\/a><\/p>\n<p><a href=\"https:\/\/www.linkedin.com\/in\/devinschumacher\" rel=\"nofollow noopener\" target=\"_blank\"><\/a><\/p>\n<hr>\n<h5><strong>More free tools &amp; stuff @&nbsp;<\/strong><a href=\"https:\/\/devinschumacher.com\" rel=\"nofollow noopener\" target=\"_blank\">devinschumacher.com<\/a><\/h5>\n<\/p><\/div>\n<\/section>\n<section id=\"video\">\n<h2> Video<\/h2>\n<div class=\"video-content\">\n<div class=\"iframe-container\"> <iframe src=\"https:\/\/www.youtube.com\/embed\/-j6y-5t37os?modestbranding=1&amp;showinfo=0\" frameborder=\"0\" allowfullscreen=\"true\"> <\/iframe>\n  <\/div>\n<\/p><\/div>\n<\/section>\n<section id=\"article\">\n<h2> Article<\/h2>\n<div class=\"text-content\">\n<ul>\n<li><a href=\"https:\/\/devinschumacher.com\/how-to-setup-jupyter-notebook-virtual-environment-vs-code-kernels\/\" rel=\"nofollow noopener\" target=\"_blank\">How To Setup Jupyter Notebook in VS Code (w\/ Virtual Env &amp; Kernels)<\/a><\/li>\n<\/ul><\/div>\n<\/section>\n<section id=\"feeling-generous\">\n<h2> Feeling Generous<\/h2>\n<div class=\"text-content\">\n<h5> <strong>SUPPORT THIS CHANNEL<br \/><\/strong><strong><\/strong><strong> <\/strong><strong>GET AWESOME STUFF&nbsp;<\/strong><\/h5>\n<hr>\n<p>Amazon\u2122 pays commissions if I refer people to them, and that person buys something (anything) over the next 24 hours...<\/p>\n<p>So if you click on one of the affiliate links below buy some crap  you need\/want - I'll get a commission from Amazon\u2122 - you'll get a great excuse to buy that 'thing' you've been wanting!<\/p>\n<p>You don't even need to buy the actual items linked here to support this channel...<\/p>\n<p>You can just buy yourself something you've been wanting, or do your weekly shopping!<\/p>\n<p>(i know you've been trying to squeeze that last little bit of toothpaste from the tube for like 3 months now... it's time for a new one)<\/p>\n<p> <strong>Toothpaste<\/strong>: <a href=\"https:\/\/amzn.to\/3iVK9oB\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/amzn.to\/3iVK9oB<\/a><\/p>\n<hr>\n<p>And that's what I call a win-win!<\/p>\n<p>hi-five amigo! <\/p>\n<\/p><\/div>\n<\/section>\n<section id=\"start\">\n<h2>START:<\/h2>\n<\/section>\n<section id=\"step-1--create-project-folder\">\n<h2>Step 1 - Create Project Folder<\/h2>\n<div class=\"text-content\">\n<h5><strong>Create project folder<\/strong><\/h5>\n<p>First you need a project folder, so create that - you can use Finder, Terminal, or do it in VS Code.<\/p>\n<\/p><\/div>\n<div class=\"text-content\">\n<pre># syntax <br>mkdir &lt;folder name&gt; <br><br># example<br>mkdir myproject<\/pre>\n<\/p><\/div>\n<\/section>\n<section id=\"step-2--create--activate-your-venv\">\n<h2>Step 2 - Create &amp; Activate Your venv<\/h2>\n<div class=\"text-content\">\n<h4><strong>Create<\/strong><\/h4>\n<p>Navigate to \/ open your project folder and create a virtual environment inside of it.<\/p>\n<\/p><\/div>\n<div class=\"text-content\">\n<pre># syntax<br>python3 -m venv &lt;virtual environment name&gt;<br><br># example that would create a virtual environment named 'myenv'<br>python3 -m venv myenv<\/pre>\n<\/p><\/div>\n<div class=\"text-content\">\n<hr>\n<\/p><\/div>\n<div class=\"text-content\">\n<h4><strong>Activate<\/strong><\/h4>\n<p>Now activate the virtual environment and when VS CODE prompts you to set it as default for the project, hit yes.<\/p>\n<\/p><\/div>\n<div class=\"text-content\">\n<pre># syntax<br>source &lt;virtual environment name&gt;\/bin\/activate<br><br># example<br>source myenv\/bin\/activate<\/pre>\n<\/p><\/div>\n<\/section>\n<section id=\"step-3--install-ipykernel\">\n<h2>Step 3 - Install ipykernel<\/h2>\n<div class=\"text-content\">\n<p>Now that your virtual environment is activated, install&nbsp;<code>ipykernel<\/code><\/p>\n<pre>pip3 install ipykernel<\/pre>\n<\/p><\/div>\n<\/section>\n<section id=\"step-4--create-a-kernel\">\n<h2>Step 4 - Create A Kernel<\/h2>\n<div class=\"text-content\">\n<p><strong>Now you can create a new kernel to be used for your project:<\/strong><\/p>\n<\/p>\n<pre># syntax<br>python3 -m ipykernel install --user --name=&lt;projectname&gt; <br><br># example that will create a kernel named 'myproject'<br>python3 -m ipykernel install --user --name=myproject<\/pre>\n<\/p><\/div>\n<\/section>\n<section id=\"step-5--start-jupyter\">\n<h2>Step 5 - Start Jupyter<\/h2>\n<div class=\"text-content\">\n<p>Start jupyter by running the command <code>jupyter notebook<\/code><\/p>\n<\/p><\/div>\n<div class=\"text-content\">\n<hr>\n<\/p><\/div>\n<div class=\"text-content\">\n<p>f you did this right you should see something like this in your terminal:<\/p>\n<\/p><\/div>\n<div class=\"image-content\">\n<figure> <a href=\"https:\/\/www.process.st\/templates\/wp-content\/uploads\/2024\/02\/kcOl-nPZd9kJHsxekRtGSQ.png\" alt=\"Step 5 - Start Jupyter\" target=\"_blank\" rel=\"noopener\"> <img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.process.st\/templates\/wp-content\/uploads\/2024\/02\/kcOl-nPZd9kJHsxekRtGSQ.png\"> <\/a><br \/>\n  <\/figure>\n<\/p><\/div>\n<\/section>\n<section id=\"step-6--trust--select-your-kernel\">\n<h2>Step 6 - Trust &amp; Select Your Kernel<\/h2>\n<div class=\"text-content\">\n<p>Now you can assign the kernel to the project in VS CODE.<\/p>\n<\/p><\/div>\n<div class=\"text-content\">\n<p>Step 6.1: Create a new Jupyter notebook<\/p>\n<ul>\n<li>Open the VSCODE search bar:&nbsp;<code>cmd+shift+p<\/code><\/li>\n<li>Type in &amp; choose: \u201cCreate: New Jupyter Notebook\u201d<\/li>\n<\/ul>\n<p>Step 6.2: Choose your kernel<\/p>\n<ul>\n<li>Open the VSCODE search bar:&nbsp;<code>cmd+shift+p<\/code><\/li>\n<li>Type in &amp; choose: \u201cNotebook: Select Notebook Kernel\u201d<\/li>\n<\/ul><\/div>\n<div class=\"text-content\">\n<p><em>At the bottom of VSCode, you should see \u201cJupyter Server: Local\u201d<\/em><\/p>\n<p>Click that, and a dropdown will appear.<\/p>\n<p>Now, you will simply enter one of the URLs you received when you ran the Jupyter command back in Step 5:<\/p>\n<\/p><\/div>\n<div class=\"image-content\">\n<figure> <a href=\"https:\/\/www.process.st\/templates\/wp-content\/uploads\/2024\/02\/rOLhFC15dFFUWXzxutFMhw.png\" alt=\"Step 6 - Trust &amp; Select Your Kernel\" target=\"_blank\" rel=\"noopener\"> <img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.process.st\/templates\/wp-content\/uploads\/2024\/02\/rOLhFC15dFFUWXzxutFMhw.png\"> <\/a><br \/>\n  <\/figure>\n<\/p><\/div>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u200d Overview HOW TO SETUP JUPYTER NOTEBOOK IN VS CODE (W\/ VIRTUAL ENV &amp; KERNELS) Figuring out how to how setup a&nbsp;jupyter notebook&nbsp;is pretty easy \u2013 you just open your terminal, install jupyter &amp; run&nbsp;jupyter notebook. But figuring out how to do it inside of VS CODE was not very intuitive (at least not for [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":29302,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"ep_exclude_from_search":false,"cover_icon_emoji":"","cover_icon_url":"","tasks_count":"12","template_description":"Figuring out how to how setup a jupyter notebook is pretty easy - you just open your terminal, install jupyter &amp; run jupyter notebook. Here's my step by step process.","template_id":"l5fLOcKolIZfjK0I-hJKxQ","task_0":"\u200d Overview","task_slug_0":"overview","task_1":"Hey there!","task_slug_1":"hey-there","task_2":"Video","task_slug_2":"video","task_3":"Article","task_slug_3":"article","task_4":"Feeling Generous","task_slug_4":"feeling-generous","task_5":"START:","task_slug_5":"start","task_6":"Step 1 - Create Project Folder","task_slug_6":"step-1--create-project-folder","task_7":"Step 2 - Create &amp; Activate Your venv","task_slug_7":"step-2--create--activate-your-venv","task_8":"Step 3 - Install ipykernel","task_slug_8":"step-3--install-ipykernel","task_9":"Step 4 - Create A Kernel","task_slug_9":"step-4--create-a-kernel","task_10":"Step 5 - Start Jupyter","task_slug_10":"step-5--start-jupyter","task_11":"Step 6 - Trust &amp; Select Your Kernel","task_slug_11":"step-6--trust--select-your-kernel","task_12":"","task_slug_12":"","task_13":"","task_slug_13":"","task_14":"","task_slug_14":"","task_15":"","task_slug_15":"","task_16":"","task_slug_16":"","task_17":"","task_slug_17":"","task_18":"","task_slug_18":"","task_19":"","task_slug_19":"","task_20":"","task_slug_20":"","task_21":"","task_slug_21":"","task_22":"","task_slug_22":"","task_23":"","task_slug_23":"","task_24":"","task_slug_24":"","task_25":"","task_slug_25":"","task_26":"","task_slug_26":"","task_27":"","task_slug_27":"","task_28":"","task_slug_28":"","task_29":"","task_slug_29":"","task_30":"","task_slug_30":"","task_31":"","task_slug_31":"","task_32":"","task_slug_32":"","task_33":"","task_slug_33":"","task_34":"","task_slug_34":"","task_35":"","task_slug_35":"","task_36":"","task_slug_36":"","task_37":"","task_slug_37":"","task_38":"","task_slug_38":"","task_39":"","task_slug_39":"","task_40":"","task_slug_40":"","task_41":"","task_slug_41":"","task_42":"","task_slug_42":"","task_43":"","task_slug_43":"","task_44":"","task_slug_44":"","task_45":"","task_slug_45":"","task_46":"","task_slug_46":"","task_47":"","task_slug_47":"","task_48":"","task_slug_48":"","task_49":"","task_slug_49":"","task_50":"","task_slug_50":"","task_51":"","task_slug_51":"","task_52":"","task_slug_52":"","task_53":"","task_slug_53":"","task_54":"","task_slug_54":"","task_55":"","task_slug_55":"","task_56":"","task_slug_56":"","task_57":"","task_slug_57":"","task_58":"","task_slug_58":"","task_59":"","task_slug_59":"","task_60":"","task_slug_60":"","task_61":"","task_slug_61":"","task_62":"","task_slug_62":"","task_63":"","task_slug_63":"","task_64":"","task_slug_64":"","task_65":"","task_slug_65":"","task_66":"","task_slug_66":"","task_67":"","task_slug_67":"","task_68":"","task_slug_68":"","task_69":"","task_slug_69":"","task_70":"","task_slug_70":"","task_71":"","task_slug_71":"","task_72":"","task_slug_72":"","task_73":"","task_slug_73":"","task_74":"","task_slug_74":"","task_75":"","task_slug_75":"","task_76":"","task_slug_76":"","task_77":"","task_slug_77":"","task_78":"","task_slug_78":"","task_79":"","task_slug_79":"","task_80":"","task_slug_80":"","task_81":"","task_slug_81":"","task_82":"","task_slug_82":"","task_83":"","task_slug_83":"","task_84":"","task_slug_84":"","task_85":"","task_slug_85":"","task_86":"","task_slug_86":"","task_87":"","task_slug_87":"","task_88":"","task_slug_88":"","task_89":"","task_slug_89":"","task_90":"","task_slug_90":"","task_91":"","task_slug_91":"","task_92":"","task_slug_92":"","task_93":"","task_slug_93":"","task_94":"","task_slug_94":"","task_95":"","task_slug_95":"","task_96":"","task_slug_96":"","task_97":"","task_slug_97":"","task_98":"","task_slug_98":"","task_99":"","task_slug_99":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-29301","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-miscellaneous"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/posts\/29301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/comments?post=29301"}],"version-history":[{"count":0,"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/posts\/29301\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/media\/29302"}],"wp:attachment":[{"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/media?parent=29301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/categories?post=29301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.process.st\/templates\/wp-json\/wp\/v2\/tags?post=29301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}