<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://jitendrachamoli.com</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 17:29:33 GMT</lastBuildDate><atom:link href="https://jitendrachamoli.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Getting started with Python]]></title><description><![CDATA[Python is a very popular programming language these days. It is commonly used to develop websites, software, task automation, data analysis and data visualization.
In this blog, we will cover how to set up a development environment for Python.
Instal...]]></description><link>https://jitendrachamoli.com/getting-started-with-python</link><guid isPermaLink="true">https://jitendrachamoli.com/getting-started-with-python</guid><category><![CDATA[Python]]></category><dc:creator><![CDATA[Jitendra Chamoli]]></dc:creator><pubDate>Sun, 02 Apr 2023 00:48:29 GMT</pubDate><content:encoded><![CDATA[<p>Python is a very popular programming language these days. It is commonly used to develop websites, software, task automation, data analysis and data visualization.</p>
<p>In this blog, we will cover how to set up a development environment for Python.</p>
<h1 id="heading-installing-python-on-macos">Installing Python on MacOS</h1>
<p>There are multiple ways to install python these days. However, we will use <a target="_blank" href="https://brew.sh/"><strong>Homebrew</strong></a><strong>,</strong> a package manager for MacOS to install Python on MacOS.</p>
<h2 id="heading-install-homebrew"><strong>Install Homebrew</strong></h2>
<p>Paste the following command in the MacOS terminal to install Homebrew</p>
<pre><code class="lang-bash">$ /bin/bash -c <span class="hljs-string">"<span class="hljs-subst">$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)</span>"</span>
</code></pre>
<h2 id="heading-install-pyenv"><strong>Install pyenv</strong></h2>
<p>The best way to manage python versions on Mac is by installing a simple python version management tool which can be installed on many operating systems mentioned <a target="_blank" href="https://github.com/pyenv/pyenv/wiki">here</a>.</p>
<p>To install it on MacOS using Homebrew use the following command:</p>
<pre><code class="lang-bash">$ brew install pyenv
</code></pre>
<p>You want <strong>pyenv</strong> to run every time you open your prompt, so include the following in your configuration files (by default on MacOS, this is <strong>.bash_profile</strong> in your home directory):</p>
<p>Use the following command to edit the bash profile on MacOS</p>
<pre><code class="lang-bash">$ vi ~/.bash_profile
</code></pre>
<p>By adding these lines, every new terminal will initiate <strong>pyenv</strong> to manage the <strong>PATH</strong> environment variable in your terminal and insert the version of Python you want to run</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">cd</span> ~/
$ <span class="hljs-built_in">echo</span> <span class="hljs-string">'eval "$(pyenv init -)"'</span> &gt;&gt; .bash_profile
</code></pre>
<p>Before installing your preferred version of Python, you'll want to install a couple of helpful tools:</p>
<pre><code class="lang-bash">$  brew install zlib sqlite
</code></pre>
<p>The <a target="_blank" href="https://zlib.net/"><strong>zlib</strong></a> compression algorithm and the <a target="_blank" href="https://www.sqlite.org/index.html"><strong>SQLite</strong></a> database are dependencies for <strong>pyenv</strong> and often <a target="_blank" href="https://github.com/pyenv/pyenv/wiki/common-build-problems#build-failed-error-the-python-zlib-extension-was-not-compiled-missing-the-zlib">cause build problems</a> when not configured correctly.</p>
<p>Add these exports to your current terminal window to ensure the installation completes:</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">export</span> LDFLAGS=<span class="hljs-string">"-L/usr/local/opt/zlib/lib -L/usr/local/opt/sqlite/lib"</span>
$ <span class="hljs-built_in">export</span> CPPFLAGS=<span class="hljs-string">"-I/usr/local/opt/zlib/include -I/usr/local/opt/sqlite/include"</span>
</code></pre>
<p>Now after the above pre-requisite are complete, it's time to install a preferred version of Python.</p>
<h2 id="heading-install-python"><strong>Install python</strong></h2>
<p>We will install the latest version available which is 3.10.10 as of writing.</p>
<pre><code class="lang-bash">$ pyenv install 3.10.10
</code></pre>
<h2 id="heading-add-virtual-environment">Add Virtual Environment</h2>
<p>Next, make this version as default version to be used globally:</p>
<pre><code class="lang-bash">$ pyenv global 3.10.10
<span class="hljs-comment"># Be sure to keep the $() syntax in this command so it can evaluate</span>
$ $(pyenv <span class="hljs-built_in">which</span> python3) -m pip install virtualenvwrapper
</code></pre>
<p>Open your <strong>.bash_profile</strong> again and add the following to be sure it works each time you open a new terminal:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Virtual environment directory</span>
$ <span class="hljs-built_in">echo</span> <span class="hljs-string">'export WORK_HOME=~/.virtualenvs'</span> &gt;&gt; .bash_profile
<span class="hljs-comment"># Make a virtual environment directory, If one does not already exist</span>
$ <span class="hljs-built_in">echo</span> <span class="hljs-string">'mkdir -p $WORK_HOME'</span> &gt;&gt; .bash_profile
<span class="hljs-comment"># Activate the new virtual environment by calling this script</span>
$ <span class="hljs-built_in">echo</span> <span class="hljs-string">'. ~/.pyenv/versions/3.10.10/bin/virtualenvwrapper.sh'</span> &gt;&gt; .bash_profile
</code></pre>
<p>Close the terminal and open a new one (or run <strong>exec /bin/bash -l</strong> to refresh the current terminal session), and you'll see <strong>virtualenvwrapper</strong> initializing the environment:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">exec</span> /bin/bash -l
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680493353967/7f4e5edc-25b1-435b-ba02-b8e1f10b314c.png" alt="Virtual Environment Setup - Installing virtualenvwrapper" class="image--center mx-auto" /></p>
<p>It will show output like the above to set up a virtual environment. Now we can set up a test environment.</p>
<pre><code class="lang-bash">mkvirtualenv test1
</code></pre>
<p>The above command will create a test1 environment and you can also switch between multiple virtual environments.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680494087874/23170a50-2bcb-4463-82c4-8ea0d6a44097.png" alt="WORK_HOME directly Setup on Terminal" class="image--center mx-auto" /></p>
<p>To exit from the current virtual environment, use <strong>deactivate</strong> command and remove any existing virtual environment use <strong>rmvirtualenv</strong> command.</p>
<p>To work on an existing virtual environment use <strong>workon</strong> command to switch to that virtual environment.</p>
<pre><code class="lang-bash">$ workon venv_name
</code></pre>
<p>That's it, the development environment setup is complete. In case, you would like to use any specific python version in another python virtual environment. Use the following command:</p>
<pre><code class="lang-bash">mkvirtualenv -p python3.9 test3
</code></pre>
<p>Thank you. See you in the next blog.</p>
<h3 id="heading-references"><strong>References:</strong></h3>
<ul>
<li><p><a target="_blank" href="https://en.wikipedia.org/wiki/Python_(programming_language)">https://en.wikipedia.org/wiki/Python_(programming_language)</a></p>
</li>
<li><p><a target="_blank" href="https://opensource.com/article/19/5/python-3-default-mac#what-to-do">https://opensource.com/article/19/5/python-3-default-mac#what-to-do</a></p>
</li>
<li><p><a target="_blank" href="https://opensource.com/article/19/6/python-virtual-environments-mac">https://opensource.com/article/19/6/python-virtual-environments-mac</a></p>
</li>
</ul>
]]></content:encoded></item></channel></rss>