<?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: Nick</title>
    <description>The latest articles on DEV Community by Nick (@hisk).</description>
    <link>https://dev.to/hisk</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%2F1877057%2F532ffc99-8704-45c0-be1b-5a0adefe4930.png</url>
      <title>DEV Community: Nick</title>
      <link>https://dev.to/hisk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hisk"/>
    <language>en</language>
    <item>
      <title>Managing Python Versions and Virtual Environments using pyenv</title>
      <dc:creator>Nick</dc:creator>
      <pubDate>Sat, 03 Aug 2024 09:17:17 +0000</pubDate>
      <link>https://dev.to/hisk/managing-python-versions-and-virtual-environments-using-pyenv-3i41</link>
      <guid>https://dev.to/hisk/managing-python-versions-and-virtual-environments-using-pyenv-3i41</guid>
      <description>&lt;p&gt;The &lt;code&gt;pyenv&lt;/code&gt; package is a very useful tool for managing multiple versions of &lt;a href="https://highskill.io/tags#python" rel="noopener noreferrer"&gt;Python&lt;/a&gt;, without too much hassle. It also comes with various plugins for streamlining the development experience, including &lt;code&gt;pyenv-virtualenv&lt;/code&gt;, which provides features for managing virtual environments and conda environments.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Unfortunately, &lt;code&gt;pyenv&lt;/code&gt; is not supported on Windows. However, we recommend using the &lt;a href="https://github.com/pyenv-win/pyenv-win" rel="noopener noreferrer"&gt;&lt;code&gt;pyenv-win&lt;/code&gt;&lt;/a&gt; fork for Windows users.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Installing &lt;code&gt;pyenv&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Install required Python build dependencies
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mac OS X&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install openssl readline sqlite3 xz zlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Ubuntu/Debian/Mint&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Alpine&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apk add --no-cache git bash build-base libffi-dev openssl-dev bzip2-dev zlib-dev readline-dev sqlite-dev 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Installing &lt;code&gt;pyenv&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The fastest way to install &lt;code&gt;pyenv&lt;/code&gt; and some of popular plugins is to use the &lt;code&gt;pyenv-installer&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl https://pyenv.run | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next up, restart your shell so the path changes take effect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exec $SHELL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Updating &lt;code&gt;pyenv&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Updating &lt;code&gt;pyenv&lt;/code&gt; is as simple as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pyenv update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Switching between Python versions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pyenv local 3.3.3&lt;/code&gt; - Sets Python 3.3.3 in the local shell.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pyenv global 2.7.3&lt;/code&gt; - Sets Python 2.7.3 globally, in all shells.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Managing virtual environments and Python versions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pyenv virtualenv 3.3.3 virtual-env-name&lt;/code&gt; - Creates a virtual environment called &lt;code&gt;virtual-env-name&lt;/code&gt; that uses Python 3.3.3&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pyenv virtualenvs&lt;/code&gt; - Shows the created virtual environments.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pyenv activate virtual-env-name&lt;/code&gt; - Activates the virtual environment with the &lt;code&gt;virtual-env-name&lt;/code&gt; name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pyenv deactivate&lt;/code&gt; - Deactivates the currently activated virtual environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Uninstalling &lt;code&gt;pyenv&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;pyenv&lt;/code&gt; executable is installed in &lt;code&gt;$PYENV_ROOT&lt;/code&gt;, which defaults to &lt;code&gt;~/.pyenv&lt;/code&gt;. To uninstall it, just simply remove it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -fr ~/.pyenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then clean up your &lt;code&gt;.bashrc&lt;/code&gt; file, by removing the following lines from it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article we've learned how simple and easy it is to use &lt;code&gt;pyenv&lt;/code&gt; and its related plugins for managing multiple versions of Python and virtual environments from a single machine.&lt;/p&gt;

&lt;p&gt;This article was originally published &lt;a href="https://highskill.io/python-pyenv-virtualenv?ref=dev.to"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
