<?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>Forem: Hafidh Fikri</title>
    <description>The latest articles on Forem by Hafidh Fikri (@hafidhfikri).</description>
    <link>https://forem.com/hafidhfikri</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%2F2187567%2F07c41435-ccf1-4070-a1c1-92744c1badae.jpg</url>
      <title>Forem: Hafidh Fikri</title>
      <link>https://forem.com/hafidhfikri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hafidhfikri"/>
    <language>en</language>
    <item>
      <title>Create Python Virtual Environment with Various Version of Python on Windows</title>
      <dc:creator>Hafidh Fikri</dc:creator>
      <pubDate>Wed, 21 May 2025 16:06:02 +0000</pubDate>
      <link>https://forem.com/hafidhfikri/create-python-virtual-environment-with-various-version-of-python-on-windows-287h</link>
      <guid>https://forem.com/hafidhfikri/create-python-virtual-environment-with-various-version-of-python-on-windows-287h</guid>
      <description>&lt;p&gt;As someone who's not too familiar with using Python, I am confused about creating multiple virtual environments with different Python versions.&lt;/p&gt;

&lt;p&gt;To solve this issue, I found a helpful library that can help me create multiple virtual environments with different Python versions. I use &lt;em&gt;pyenv&lt;/em&gt; and &lt;em&gt;pyenv-venv&lt;/em&gt; to tackle this problem, and many tutorials explain the installation process in Linux and MacOS, so I will share how to install it on Windows.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1. Install &lt;em&gt;pyenv&lt;/em&gt; and &lt;em&gt;pyenv-venv&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;Firstly, I need to install both the library by following the instructions on the git page &lt;a href="https://github.com/pyenv-win/pyenv-win" rel="noopener noreferrer"&gt;pyenv-win&lt;/a&gt; and &lt;a href="https://github.com/pyenv-win/pyenv-win-venv" rel="noopener noreferrer"&gt;pyenv-win-venv&lt;/a&gt;. For the first step,  I need to install &lt;em&gt;pyenv&lt;/em&gt; first by executing these commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Invoke-WebRequest &lt;span class="nt"&gt;-UseBasicParsing&lt;/span&gt; &lt;span class="nt"&gt;-Uri&lt;/span&gt; &lt;span class="s2"&gt;"https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1"&lt;/span&gt; &lt;span class="nt"&gt;-OutFile&lt;/span&gt; &lt;span class="s2"&gt;"./install-pyenv-win.ps1"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &amp;amp;&lt;span class="s2"&gt;"./install-pyenv-win.ps1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check that the installation was successful, I will check the version of &lt;em&gt;pyenv&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;span class="c"&gt;#Output: pyenv 3.1.1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, I need to install &lt;em&gt;pyenv-env&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Invoke-WebRequest &lt;span class="nt"&gt;-UseBasicParsing&lt;/span&gt; &lt;span class="nt"&gt;-Uri&lt;/span&gt; &lt;span class="s2"&gt;"https://raw.githubusercontent.com/pyenv-win/pyenv-win-venv/main/bin/install-pyenv-win-venv.ps1"&lt;/span&gt; &lt;span class="nt"&gt;-OutFile&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="se"&gt;\i&lt;/span&gt;&lt;span class="s2"&gt;nstall-pyenv-win-venv.ps1"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &amp;amp;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="se"&gt;\i&lt;/span&gt;&lt;span class="s2"&gt;nstall-pyenv-win-venv.ps1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And check again if the installation was successful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv-win-venv
&lt;span class="c"&gt;#Output: pyenv-win-venv v0.6.5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2. Install Python
&lt;/h4&gt;

&lt;p&gt;I will plan to install two different versions of Python, which are version 3.8.8 and 3.9.4. Before I do the installation, I need to check if the Python version that I will install are available to download with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;span class="c"&gt;#Output:&lt;/span&gt;
&lt;span class="c"&gt;#3.0.1&lt;/span&gt;
&lt;span class="c"&gt;#3.1.0&lt;/span&gt;
&lt;span class="c"&gt;#3.1.1&lt;/span&gt;
&lt;span class="c"&gt;#3.8.8&lt;/span&gt;
&lt;span class="c"&gt;#3.9.4&lt;/span&gt;
&lt;span class="c"&gt;#.....&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, if I have found the version of Python that I want to install, the next step is to install it with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Command structure&lt;/span&gt;
&lt;span class="c"&gt;#pyenv install &amp;lt;python_version&amp;gt;&lt;/span&gt;

pyenv &lt;span class="nb"&gt;install &lt;/span&gt;3.8.8
pyenv &lt;span class="nb"&gt;install &lt;/span&gt;3.9.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to make sure both Python versions have been installed and can be used to create the virtual environment by checking availability both on &lt;em&gt;pyenv&lt;/em&gt; and &lt;em&gt;pyenv-venv&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv versions
&lt;span class="c"&gt;#Output:&lt;/span&gt;
&lt;span class="c"&gt;#3.8.8&lt;/span&gt;
&lt;span class="c"&gt;#3.9.4&lt;/span&gt;

pyenv-venv list python
&lt;span class="c"&gt;#Output:&lt;/span&gt;
&lt;span class="c"&gt;#3.8.8&lt;/span&gt;
&lt;span class="c"&gt;#3.9.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, I can see both Python versions have been installed, so now I can create the virtual environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3. Create Virtual Environment
&lt;/h4&gt;

&lt;p&gt;To create a new virtual environment by defining a specific Python version,   I will execute the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Command structure&lt;/span&gt;
&lt;span class="c"&gt;#pyenv-venv install &amp;lt;python_version&amp;gt; &amp;lt;env_name&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;#pyenv-venv activate &amp;lt;env_name&amp;gt;&lt;/span&gt;

pyenv-venv &lt;span class="nb"&gt;install &lt;/span&gt;3.8.8 env_a
pyenv-venv activate env_a
python &lt;span class="nt"&gt;-V&lt;/span&gt; 
&lt;span class="c"&gt;#Output : Python 3.8.8&lt;/span&gt;
pyenv-venv deactivate

pyenv-venv &lt;span class="nb"&gt;install &lt;/span&gt;3.9.4 env_b
pyenv-venv activate env_b
python &lt;span class="nt"&gt;-V&lt;/span&gt; 
&lt;span class="c"&gt;#Output : Python 3.9.4&lt;/span&gt;
pyenv-venv deactivate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, if you want to find out what virtual environment has been created, just follow this command you can see the available virtual environment on the computer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv-venv list envs

&lt;span class="c"&gt;#Output:&lt;/span&gt;
&lt;span class="c"&gt;#Envs installed:&lt;/span&gt;
&lt;span class="c"&gt;#env_a&lt;/span&gt;
&lt;span class="c"&gt;#env_b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one of the solutions I use. I have tried using the &lt;em&gt;virtualenv&lt;/em&gt; plugin from &lt;em&gt;pyenv&lt;/em&gt;, and it turned out to be constrained in the installation, so I looked for other alternatives. I hope this article can be an alternative solution for installing various versions of Python in various virtual environments on Windows.&lt;/p&gt;

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