<?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: Fernanda Martins</title>
    <description>The latest articles on DEV Community by Fernanda Martins (@flmmartins).</description>
    <link>https://dev.to/flmmartins</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%2F1138232%2Fc4dd7c0c-a983-44da-b405-ab8f3b36445e.jpeg</url>
      <title>DEV Community: Fernanda Martins</title>
      <link>https://dev.to/flmmartins</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/flmmartins"/>
    <language>en</language>
    <item>
      <title>Pragmatic way of installing multiple versions of python with virtual environments</title>
      <dc:creator>Fernanda Martins</dc:creator>
      <pubDate>Sun, 13 Aug 2023 10:31:44 +0000</pubDate>
      <link>https://dev.to/flmmartins/pragmatic-way-of-installing-multiple-versions-of-python-with-virtual-environments-a37</link>
      <guid>https://dev.to/flmmartins/pragmatic-way-of-installing-multiple-versions-of-python-with-virtual-environments-a37</guid>
      <description>&lt;p&gt;This guide shows you a way to install multiple python versions on Mac using pyenv and to control virtual environments with pipenv.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing multiple versions of python
&lt;/h2&gt;

&lt;p&gt;To control python versions I use &lt;a href="https://github.com/pyenv/pyenv"&gt;pyenv&lt;/a&gt;. I installed it using:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;brew install pyenv&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Afterward, I added the environment variables as described in &lt;a href="https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv"&gt;pyenv GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can set versions of python with pyenv with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pyenv install 3.11.4 # Use this option for Mac Intel
arch -x86_64 pyenv install 3.11.4 # Use this option for Mac M1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can set the python for a project with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pyenv local 3.11.4&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;which will create a file in your project called .python-version&lt;/p&gt;

&lt;p&gt;Or globally with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pyenv global 3.11.4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can check versions with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pyenv versions&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also check python version with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Binaries and python versions are usually stored in ~/.pyenv&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating virtual environments
&lt;/h2&gt;

&lt;p&gt;To manage python dependencies and virtual environments I make use of pipenv&lt;/p&gt;

&lt;p&gt;Install pipenv:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install pipenv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inside your project folder you can create a virtual environment and install your packages with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pipenv install &amp;lt;a_package&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When you run this command it will install your libraries based on the python version you set in your pyenv.&lt;/p&gt;

&lt;p&gt;Since you may have several python versions on your machine, I advise you to create a virtual environment that always specifies the python version with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pipenv --python 3.11&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now with your environment created, no matter what python version is set to be your global, you can do the below command and it will automatically launch the latest created environment&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pipenv shell&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once you run the command above you will be inside a virtual environment in your terminal. To install a package you can do&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pipenv install yamllint&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create a &lt;em&gt;Pipfile&lt;/em&gt; and a &lt;em&gt;Pipfile.lock&lt;/em&gt;. The first will show the packages that you are installing and the lock file shows the packages' version hashes and their dependencies as well.&lt;/p&gt;

&lt;p&gt;If you would like to know more about pipenv and dependency resolution I advise you to read &lt;a href="https://realpython.com/pipenv-guide/"&gt;this complete guide&lt;/a&gt; about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrating with VSCode
&lt;/h2&gt;

&lt;p&gt;Now that you have all installed via terminal you might want to integrate all that with VSCode.&lt;/p&gt;

&lt;p&gt;Install &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-python.python"&gt;Python VSCode&lt;/a&gt; and it should work, right? Well, not everything.&lt;/p&gt;

&lt;p&gt;Even though you loaded your virtual environment in the terminal, VSCode might not detect it and you will not be able to use the VSCode debugger&lt;/p&gt;

&lt;p&gt;To fix it click on item 1 from the image below and choose the virtual environment you created before. Once you click you should see the virtual environment reference in your VS Code bar.&lt;/p&gt;

&lt;p&gt;If your virtual environment is not showing up, make sure you created one by going to your project terminal and running pipenv shell. If you still cannot select it afterward, you need to tell VSCode where your environments are by going to VSCode Settings &amp;gt; Looking for venv &amp;gt; Venv Folders and add there the path of your environments. In my case that is &lt;em&gt;~/.local/share/virtualenvs/&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HQW79q4b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29q3vrsoxr3buffehri6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HQW79q4b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29q3vrsoxr3buffehri6.png" alt="VSCode image with instructions" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding environment and python version to your terminal
&lt;/h2&gt;

&lt;p&gt;You can also have information about your virtual environment displayed in your terminal together with your python version like item 3 from the image above&lt;/p&gt;

&lt;p&gt;For that, you will need to install &lt;a href="https://ohmyz.sh"&gt;https://ohmyz.sh&lt;/a&gt; and add steroids to it with &lt;a href="https://github.com/romkatv/powerlevel10k"&gt;https://github.com/romkatv/powerlevel10k&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PowerLevel10k might seem intimidating at first but there's a wizard where you can choose exactly how your terminal should be.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
