avatarM&E Technical Solutions Ltd.

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3435

Abstract

</span> Python 3.11.1</pre></div><p id="e802">Next, let’s verify where the Python was installed by typing below command:</p><div id="caba"><pre><span class="hljs-symbol">C:</span>\Users\user1&gt;<span class="hljs-keyword">where</span> python <span class="hljs-symbol">C:</span>\Program Files\Python311\python.exe <span class="hljs-symbol">C:</span>\Users\user1\AppData\Local\Microsoft\WindowsApps\python.exe</pre></div><p id="6156">Oops! Why we got two responses. Which one is the one we just installed? The answer is the first one, “C:\Program Files\Python311\python.exe”. You could find this from step 4 above, as well as below commands:</p><div id="8616"><pre><span class="hljs-symbol">C:</span>\Users\user1&gt;<span class="hljs-string">"C:\Program Files\Python311\python.exe"</span> -V Python <span class="hljs-number">3.11</span>.<span class="hljs-number">1</span>

<span class="hljs-symbol">C:</span>\Users\user1><span class="hljs-string">"C:\Users\user1\AppData\Local\Microsoft\WindowsApps\python.exe"</span> -V Python was <span class="hljs-built_in">not</span> found; run without arguments <span class="hljs-keyword">to</span> install <span class="hljs-keyword">from</span> the Microsoft Store, <span class="hljs-built_in">or</span> disable this shortcut <span class="hljs-keyword">from</span> Settings > Manage App Execution Aliases.</pre></div><p id="7817">Don’t forget the double quotes because the space insight the “Program Files” folder name.</p><p id="bac6">So, what does the second “python.exe” for? It is installed originally when your Windows Operating System being setup at beginning. It is a Microsoft App Store launcher to install Microsoft Python. Since we picks Python Official binary, we could just ignore it.</p><h1 id="5573">Linux</h1><p id="cf62">Lots of Linux comes with Python versions as part of initial installation. Before installing another Python, use below commands to find out if any python already installed. If so, what are the installed versions.</p><div id="bc2b"><pre>$ python <span class="hljs-comment">--version</span>

$ python2 <span class="hljs-comment">--version</span>

python3 <span class="hljs-comment">--version</span></pre></div><p id="7ef1">In below example, we have Python 3.10.4 installed from operating system, and latest available version for current operating system is 3.10.6.</p><div id="a99d"><pre>user1<span class="hljs-variable">@lubuntu2204a</span><span class="hljs-symbol">:~</span><span class="hljs-variable"> </span>python3 -V <span class="hljs-title class_">Python</span> <span class="hljs-number">3.10</span>.<span class="hljs-number">4</span> user1<span class="hljs-variable">@lubuntu2204a</span><span class="hljs-symbol">:</span><span class="hljs-variable">$ </span>sudo apt list -a python3 <span class="hljs-title class_">Listing</span>... <span class="hljs-title class_">Done</span> python3/jammy-updates <span class="hljs-number">3.10</span>.<span class="hljs-number">6</span>-<span class="hljs-number">1</span><span class="hljs-number">22.04</span> amd64 [upgradable <span class="hljs-symbol">from:</span> <span class="hljs-number">3.10</span>.<span class="hljs-number">4</span>-0ubuntu2] python3/jammy,now <span class="hljs-number">3.10</span>.<span class="hljs-number">4</span>-0ubuntu2 amd64 [installed,upgradable <span class="hljs-symbol">to:</span> <span class="hljs-number">3.10</span>.<span class="hljs-number">6</span>-<span class="hljs-numbe

Options

r">1</span>~<span class="hljs-number">22.04</span>]

python3/jammy-updates <span class="hljs-number">3.10</span>.<span class="hljs-number">6</span>-<span class="hljs-number">1</span>~<span class="hljs-number">22.04</span> i386 python3/jammy <span class="hljs-number">3.10</span>.<span class="hljs-number">4</span>-0ubuntu2 i386

user1<span class="hljs-variable">@lubuntu2204a</span><span class="hljs-symbol">:~</span>$</pre></div><h1 id="703d">Python venv: Create, Activate, Deactivate, and Delete</h1><p id="2406">For Linux environment, we could check if Python-venv package is installed by using below command:</p><figure id="6105"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*UbICYYflkKzHY0sAQWPeVw.png"><figcaption></figcaption></figure><p id="903b">If not found, we need find which version to install. Since venv package always go with Python version. Let’s run below command:</p><figure id="61f0"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ScdEKZLVon_lIZooBrt5uQ.png"><figcaption></figcaption></figure><p id="aeba">From above, we know our Python version is 3.10.6. And venv package for 3.10 is the most close one for us. Let’s get it installed using below command:</p><figure id="1f5d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*gXBq2XrO_xW58uf-tCtbiQ.png"><figcaption></figcaption></figure><ol><li><b>Create venv environment</b></li></ol><p id="a78d">To create a new venv environment, use command:</p><div id="4881"><pre>python3 -m venv <my venv environment name or full directory>

or

python -m venv <my venv environment name or full directory></pre></div><p id="13d4">Below is an example in Linux:</p><figure id="251d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*JMZ6DX9vHjbf596sMnvq5Q.png"><figcaption></figcaption></figure><p id="0b08">Below is an example in Windows:</p><figure id="76b2"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*eU8sV_umbkXqfGdlwmkrYg.png"><figcaption></figcaption></figure><p id="a204">2. <b>Activate a venv environment</b></p><p id="954e">To activate venv from Linux or MacOS, run below command:</p><figure id="c51c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*20jjK7ZK5bEQQpHsDGmvog.png"><figcaption></figcaption></figure><p id="e0da">To activate venv from Windows, run below command:</p><figure id="a43b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*mDATaW_kbsLCKzpAOF2wlA.png"><figcaption></figcaption></figure><p id="2779"><b>3. Deactivate a venv environment</b></p><p id="adba">The deactivate command is same between Linux, MacOS and Windows.</p><figure id="3270"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*V4UP82BDCGTOvJQhQju7Rw.png"><figcaption></figcaption></figure><p id="51e7">4. Delete a venv environment</p><p id="5896">To delete a venv environment, simply delete its directory. Make sure you do not delete an activated venv environment.</p><h1 id="ee0a">Conclusion</h1><p id="bb6e">Now you learned how to install Python 3 and how to create, activate, deactivate, and delete virtual environments. To learn more on picking right Python environments, and modernized Python development, please visit: <a href="https://readmedium.com/setup-modernized-python-development-environment-52f17a3d92c">https://readmedium.com/setup-modernized-python-development-environment-52f17a3d92c</a>.</p></article></body>

Install Python 3 with venv environments within 5 minutes

In this page, we will walk through basic installation to get Python 3 up and running for most of common operating systems.

Microsoft Windows:

To install Python 3 in Windows environment, follow below steps:

  1. Download Python installation package from Official Python website. Always select latest stable python release. In our scenario, we picked Python 3.11.1 64-bit Windows installer for our installation.

2. Run the installer after downloaded. From the first screen, check “Add python.exe to PATH”, and click on “Customize installation”.

3. Click on “Next” button on “Optional Features”.

4. Make below changes:

  • select “Install Python 3.11 for all users”. This action will make “Precompile standard library” selected as well. Keep both.
  • Select “Add Python to environment variables”.
  • Unselect “Associate files with Python”. In most of situation, we do not want to execute .py scripts by double click.
  • Unselect “Create shortcuts for installed applications”. We typically use Python and Python applications in command line (terminal) or inside IDE, not by shortcuts.

After making changes, the “Advanced Options” window will look like below screenshot. Then, click on “Install” button.

5. Depending on your computer’s speed, the installation process might take a few minutes.

When installation completed, you will see below window.

Click on “Disable path length limit” if you haven’t done so before in your computer. It is helpful especially you use the current computer for software development.

Last, click on “Close” button.

6. Next, let’s verify the installation. Open a DOS window, or search “Command Prompt” like below.

7. Enter below commands to validate Python versions we installed.

C:\Users\user1>python --version
Python 3.11.1

C:\Users\user1>python -V
Python 3.11.1

Next, let’s verify where the Python was installed by typing below command:

C:\Users\user1>where python
C:\Program Files\Python311\python.exe
C:\Users\user1\AppData\Local\Microsoft\WindowsApps\python.exe

Oops! Why we got two responses. Which one is the one we just installed? The answer is the first one, “C:\Program Files\Python311\python.exe”. You could find this from step 4 above, as well as below commands:

C:\Users\user1>"C:\Program Files\Python311\python.exe" -V
Python 3.11.1

C:\Users\user1>"C:\Users\user1\AppData\Local\Microsoft\WindowsApps\python.exe" -V
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

Don’t forget the double quotes because the space insight the “Program Files” folder name.

So, what does the second “python.exe” for? It is installed originally when your Windows Operating System being setup at beginning. It is a Microsoft App Store launcher to install Microsoft Python. Since we picks Python Official binary, we could just ignore it.

Linux

Lots of Linux comes with Python versions as part of initial installation. Before installing another Python, use below commands to find out if any python already installed. If so, what are the installed versions.

$ python --version

$ python2 --version

$ python3 --version

In below example, we have Python 3.10.4 installed from operating system, and latest available version for current operating system is 3.10.6.

user1@lubuntu2204a:~$ python3 -V
Python 3.10.4
user1@lubuntu2204a:~$ sudo apt list -a python3
Listing... Done
python3/jammy-updates 3.10.6-1~22.04 amd64 [upgradable from: 3.10.4-0ubuntu2]
python3/jammy,now 3.10.4-0ubuntu2 amd64 [installed,upgradable to: 3.10.6-1~22.04]

python3/jammy-updates 3.10.6-1~22.04 i386
python3/jammy 3.10.4-0ubuntu2 i386

user1@lubuntu2204a:~$

Python venv: Create, Activate, Deactivate, and Delete

For Linux environment, we could check if Python-venv package is installed by using below command:

If not found, we need find which version to install. Since venv package always go with Python version. Let’s run below command:

From above, we know our Python version is 3.10.6. And venv package for 3.10 is the most close one for us. Let’s get it installed using below command:

  1. Create venv environment

To create a new venv environment, use command:

python3 -m venv <my venv environment name or full directory>

or 

python -m venv <my venv environment name or full directory>

Below is an example in Linux:

Below is an example in Windows:

2. Activate a venv environment

To activate venv from Linux or MacOS, run below command:

To activate venv from Windows, run below command:

3. Deactivate a venv environment

The deactivate command is same between Linux, MacOS and Windows.

4. Delete a venv environment

To delete a venv environment, simply delete its directory. Make sure you do not delete an activated venv environment.

Conclusion

Now you learned how to install Python 3 and how to create, activate, deactivate, and delete virtual environments. To learn more on picking right Python environments, and modernized Python development, please visit: https://readmedium.com/setup-modernized-python-development-environment-52f17a3d92c.

Python
Venv
Virtualenv
Recommended from ReadMedium