<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Elizabeth Thuku</title>
    <description>The latest articles on DEV Community by Elizabeth Thuku (@lizawt).</description>
    <link>https://dev.to/lizawt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F863852%2F1da6ff96-e989-4057-8288-f1d445480369.png</url>
      <title>DEV Community: Elizabeth Thuku</title>
      <link>https://dev.to/lizawt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lizawt"/>
    <language>en</language>
    <item>
      <title>How to create a conda environment that imports all Python libraries in Jupiter notebooks</title>
      <dc:creator>Elizabeth Thuku</dc:creator>
      <pubDate>Fri, 24 Jun 2022 12:45:01 +0000</pubDate>
      <link>https://dev.to/lizawt/how-to-create-a-conda-environment-that-imports-all-python-libraries-in-jupiter-notebooks-377n</link>
      <guid>https://dev.to/lizawt/how-to-create-a-conda-environment-that-imports-all-python-libraries-in-jupiter-notebooks-377n</guid>
      <description>&lt;p&gt;When I first started working with conda environments in windows 10, it took me a very long time to figure out how to import basic python libraries in Jupiter notebooks without having to install them one by one any time I needed it.&lt;/p&gt;

&lt;p&gt;Even tried cloning the base environment to a .yaml file but that didn't work either.&lt;/p&gt;

&lt;p&gt;so what finally worked? &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating conda environments from a text file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first thing to note with this method is we need to start with an existing working environment. its some sort of cloning but not really. &lt;/p&gt;

&lt;p&gt;for me I'll be "cloning" the base environment in conda.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In your anaconda or command prompt activate the environment you &lt;br&gt;
need to duplicate: &lt;code&gt;conda activate base&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run &lt;code&gt;conda list --explicit&lt;/code&gt; to see a list of specs in the &lt;br&gt;
active environment like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zVPZFrCO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otqq7wthoriet5vsrr0i.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zVPZFrCO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otqq7wthoriet5vsrr0i.jpg" alt="packages list" width="840" height="220"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save the list in a text file by running&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;conda list --explicit &amp;gt; pack-file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A thing to note with explicit files is that they are not cross platform. The &lt;code&gt;# platform: win-64&lt;/code&gt; shows where the file was created and can only be used within the same platform since we'll be installing the packages from the text file and dependency issues may arise.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new empty environment &lt;em&gt;mtest&lt;/em&gt;. Replace &lt;em&gt;mtest&lt;/em&gt; with 
name of your choice
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;conda create --name mtest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Locate the pack-file.txt from your directory and remove any 
packages you don't want installed in the new environment. Make 
sure ipykernel is in the list if you want Jupiter notebooks to 
work correctly in the environment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember if you are duplicating the base environment you need to locate the following packages and remove them from the file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--utdGXaC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/omkvxkk0wyhjtw8i1295.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--utdGXaC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/omkvxkk0wyhjtw8i1295.jpg" alt="Remove this" width="880" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deactivate the active environments and make sure there is no 
environment enclosed in () before your folder path:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IEdJHwjh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysictljxv5hwhlxbyshz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IEdJHwjh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysictljxv5hwhlxbyshz.jpg" alt="env deactivation" width="880" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run this to install the packages in the new environment
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;conda install --name mtest --file pack-file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Conda does not check architecture or dependencies when installing from a txt file. To ensure that the packages work correctly, make sure that the file was created from a working environment, and use it on the same architecture, operating system, and platform, such as linux-64,osx-64 or win-64.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The final step is to link your environment to jupyter using kernels. Activate your environment &lt;code&gt;conda activate mtest&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m ipykernel install --user --name=mtest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jSxCyUZg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cuaoty0t5y11n0jm5np9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jSxCyUZg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cuaoty0t5y11n0jm5np9.jpg" alt="Link jupyter" width="880" height="65"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the kernel can be found in your Jupyter notebooks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kevq08HF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m5ahgotmmh7u6kbw0slj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kevq08HF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m5ahgotmmh7u6kbw0slj.jpg" alt="Available kernel" width="870" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you go! I hope this was helpful. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
