{"id":6906,"date":"2024-04-11T11:58:21","date_gmt":"2024-04-11T11:58:21","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=6906"},"modified":"2024-04-11T11:58:21","modified_gmt":"2024-04-11T11:58:21","slug":"setting-up-virtual-environment-in-python","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/setting-up-virtual-environment-in-python\/","title":{"rendered":"Setting Up Virtual Environment in Python"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#how-to-set-a-local-environment\">How to Set a Local Environment<\/a><\/li><li ><a href=\"#how-to-install-python\">How to install Python?<\/a><\/li><li ><a href=\"#how-to-install-python-on-ubuntu-linux\">How to install Python on Ubuntu Linux?<\/a><ul><li ><a href=\"#how-to-use-the-yum-command\">How to use the Yum command<\/a><\/li><\/ul><\/li><li ><a href=\"#how-to-install-python-on-windows\">How to install Python on Windows?<\/a><\/li><li ><a href=\"#how-to-install-macintosh\">How to install Macintosh?<\/a><\/li><li ><a href=\"#how-to-set-up-path\">How to set up Path?<\/a><\/li><li ><a href=\"#how-to-set-up-path-at-unix-linux\">How To Set Up Path at Unix\/Linux?<\/a><\/li><li ><a href=\"#how-to-set-a-path-at-windows\">How to set a path at Windows?<\/a><\/li><li ><a href=\"#what-are-the-python-environment-variables\">What are the Python Environment Variables<\/a><\/li><li ><a href=\"#how-to-run-python\">How to Run Python?<\/a><\/li><li ><a href=\"#how-to-add-the-script-from-the-command-line\">How to add the Script from the command line<\/a><\/li><li ><a href=\"#integrated-development-environment\">Integrated Development Environment<\/a><\/li><li ><a href=\"#conclusion\">Conclusion<\/a><\/li><li ><a href=\"#setting-up-virtual-environment-in-python-fa-qs\">Setting Up Virtual Environment in Python-FAQs<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<p>The Python Virtual Environment System is a tool that functions to confirm that packages on different projects and, will be saved in different places as they won&#8217;t conflict. <\/p>\n\n\n\n<p>However, the Python virtual environment will be kept in an isolated place from other projects as it has their dependencies for staying independent. This tutorial will tell you how to set the virtual Environment in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-set-a-local-environment\">How to Set a Local Environment<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, you have to open the terminal window and then type <a href=\"https:\/\/www.skillvertex.com\/blog\/how-does-a-python-interpreter-works\/\" data-type=\"post\" data-id=\"6895\">Python <\/a>to check if the version is already installed.<\/li>\n\n\n\n<li>If it is already installed, it is possible to get a message similar to that provided below:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>$ python\nPython 3.11.2 (main, Feb 8 2023, 14:49:24) &#91;GCC 9.4.0] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\n&gt;&gt;&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-install-python\">How to install Python?<\/h2>\n\n\n\n<p>The recent source, binaries, and documentation will be available on the official website of Python <a href=\"https:\/\/www.python.org\/\" data-type=\"link\" data-id=\"https:\/\/www.python.org\/\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/www.python.org\/<\/a>.Python documentation can be downloaded from their website. Their documentation will be accessible in<a href=\"https:\/\/www.skillvertex.com\/blog\/how-to-learn-html\/\" data-type=\"post\" data-id=\"1577\"> HTML<\/a>, PDF, and PostScript formats.<\/p>\n\n\n\n<p>Moreover, python distribution will be accessible on a wide range of platforms. Download only the binary code that applies to your platform and then install Python. But, if the binary code is not accessible on the platform, then use the C Compiler to compile the source manually. Through compiling the source code, it will provide flexibility depending on the features that are necessary for the installation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-install-python-on-ubuntu-linux\">How to install Python on Ubuntu Linux?<\/h2>\n\n\n\n<p>follow these steps to check if the python is already installed or not <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go and open the Linux terminal<\/li>\n\n\n\n<li>Then, type the given below<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>$ python3.11 --version<\/code><\/pre>\n\n\n\n<p>Use the apt-Advanced Packaging Tool to install Python easily. Keep in mind to update the packages list in every configured repository.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo apt update<\/code><\/pre>\n\n\n\n<p>The Recent version won&#8217;t be there to install after doing the updation. To resolve this issue, add the dead snakes repository.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo apt-get install software-properties-common\n$ sudo add-apt-repository ppa:deadsnakes\/ppa<\/code><\/pre>\n\n\n\n<p>Consider updating the package list once more.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo apt update<\/code><\/pre>\n\n\n\n<p>Type the command given below to install the<a href=\"https:\/\/www.skillvertex.com\/blog\/python-applications\/\" data-type=\"post\" data-id=\"6890\"> Python 3.11 version<\/a> in the terminal. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo apt-get install python3.11<\/code><\/pre>\n\n\n\n<p>Check if the Python is installed correctly by entering the command given below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ python3\nPython 3.11.2 (main, Feb 8 2023, 14:49:24) &#91;GCC 9.4.0] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\n&gt;&gt;&gt; print (\"Hello World\")\nHello World\n\n&gt;&gt;&gt;<\/code><\/pre>\n\n\n\n<p><strong>Install Python On Other Linux<\/strong><\/p>\n\n\n\n<p>The steps to install Python on a Unix or Linux machine are the follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open a website and then click the download link. <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/www.python.org\/downloads\/<\/a>.<\/li>\n\n\n\n<li>Then, go to the link for installing the zipped <a href=\"https:\/\/www.skillvertex.com\/blog\/how-to-work-with-unicode-in-python\/\" data-type=\"post\" data-id=\"6901\">source code<\/a> which is available on the Unix\/ Linux.<\/li>\n\n\n\n<li>The next step is to install and extract files<\/li>\n\n\n\n<li>followed by editing the modules for customizing those options.<\/li>\n<\/ul>\n\n\n\n<p>Then, enter the command given below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ run .\/configure script\n$ make\n$ make install<\/code><\/pre>\n\n\n\n<p>Install the Python from the standard location which is  <em>\/usr\/local\/bin<\/em>  and their libraries in  <em>\/usr\/local\/lib\/pythonXX<\/em> . Here, XX is considered as the version of Python.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-use-the-yum-command\">How to use the Yum command<\/h3>\n\n\n\n<p>Red Hat Enterprise Linux won&#8217;t install Python 3 . Instead will use the yum command on CentOS and other related variants. The command to install <a href=\"https:\/\/www.skillvertex.com\/blog\/python-tutorial\/\" data-type=\"post\" data-id=\"6852\">Python-3<\/a>  RHEL 8 are the following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo yum install python3\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-install-python-on-windows\">How to install Python on Windows?<\/h2>\n\n\n\n<p>Python&#8217;s version 3.10  cannot be installed on Windows 7. It is suggested to install Python from the official installer. Another way is to install from the  <a href=\"https:\/\/www.python.org\/downloads\/windows\/\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/www.python.org\/downloads\/windows\/<\/a><\/p>\n\n\n\n<p>The embedded packages and installers for 32 and 64-bit architecture are provided below<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/python\/images\/embeddable_packages.jpg\" alt=\"embeddable_packages\"\/><\/figure>\n\n\n\n<p>Install the 64-bit Windows <\/p>\n\n\n\n<p>(<a href=\"https:\/\/www.python.org\/ftp\/python\/3.11.2\/python-3.11.2-amd64.exe\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/www.python.org\/ftp\/python\/3.11.2\/python-3.11.2-amd64.exe<\/a>)<\/p>\n\n\n\n<p>Click the downloaded  file to start the installation<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/python\/images\/installation.jpg\" alt=\"Image-9.jpg\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Then, click the Install Now button and select the installation folder which has a shorter path. Then, tick the second check box for updating the path variable.<\/p>\n\n\n\n<p>The next step is to accept defaults which are available on the installation wizard for the installation to be completed.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/python\/images\/complete_installation.jpg\" alt=\"Image-10\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Then, open the Window Command Prompt terminal for running the Python for running the python and to find out the installation success.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\Users\\Acer&gt;python\nPython 3.11.2 (tags\/v3.11.2:878ead1, Feb 7 2023, 16:38:35) &#91;MSC v.1934\n64 bit (AMD64)] on win32\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n&gt;&gt;&gt;<\/code><\/pre>\n\n\n\n<p>Python standard <a href=\"https:\/\/www.skillvertex.com\/blog\/c-library-math-h-functions\/\" data-type=\"post\" data-id=\"2596\">library<\/a> consists of an executable module known as IDLE (Integrated Development and Learning Environment). Check it in the <a href=\"https:\/\/www.skillvertex.com\/blog\/which-of-the-following-windows-server-roles-are-not-supported-on-azure-virtual-machines\/\" data-type=\"post\" data-id=\"2646\">Windows<\/a> start menu and then begin to launch.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/python\/images\/idle.jpg\" alt=\"idle\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>IDLE consists of a Python shell and a customizable multi-window texter which has several features like syntax highlighting, smart indent, and auto-completion.  It is considered a cross-platform that will perform on Windows, MacOS, and Linux. Additionally, it consists of a debugger that is required for setting up the breakpoints, stepping, and viewing the global and local namespaces.<\/p>\n\n\n\n<p>The steps to install Python on a Windows machine are the follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, open the web browser and then go to <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/www.python.org\/downloads\/<\/a>.<\/li>\n\n\n\n<li>Go to the link of the Windows installer &nbsp;python-XYZ.msi&nbsp;file. Where XYZ is the version that is required to be installed.<\/li>\n\n\n\n<li>The Windows system should support the <a href=\"https:\/\/www.skillvertex.com\/blog\/which-service-gives-microsoft-azure-users-access-to-the-open-source-framework-hadoop\/\" data-type=\"post\" data-id=\"1747\">Microsoft <\/a>Installer 2.0 save the installer file to the local machine and run the installer to check if the machine will support MSI.<\/li>\n\n\n\n<li>Run the installed file. It will open the Python install wizard and is easy. Accept the default settings and then need to wait till the installation is complete.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-install-macintosh\">How to install Macintosh?<\/h2>\n\n\n\n<p>Macs will have Python already installed. But the dates won&#8217;t be correctly updated. Check <a href=\"https:\/\/www.python.org\/download\/mac\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">http:\/\/www.python.org\/download\/mac\/<\/a>&nbsp; for knowing the steps to install the current version with the tool to support the development of Mac. The older Mac Os was introduced in 2003.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-set-up-path\">How to set up Path?<\/h2>\n\n\n\n<p>Programs and other executable files will be available in several directories. Hence, the Operating system will give a search path that can list out the directories and so, the OS Searches will be available for executables.<\/p>\n\n\n\n<p>Moreover, this path is stored in an environment variable which is named string that is operated by the operating system. The <a href=\"https:\/\/www.skillvertex.com\/blog\/variable-length-arguments-for-macros\/\" data-type=\"post\" data-id=\"3327\">variable<\/a> has information that is accessible to the command shell and other programs. The path variable is provided name as PATH in Unix or Path in Windows.<\/p>\n\n\n\n<p>In<a href=\"https:\/\/www.skillvertex.com\/blog\/in-which-operating-system-we-can-use-azure-cli\/\" data-type=\"post\" data-id=\"3256\"> Mac OS<\/a>, the installer can modify the path details. To get the Python interpreter from a particular directory. It is necessary to add the Python directory to your path.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-set-up-path-at-unix-linux\">How To Set Up Path at Unix\/Linux?<\/h2>\n\n\n\n<p>follow the steps to add the Python directory to the path for a particular session in Unix :<\/p>\n\n\n\n<p>a. In the csh shell- enter setenv PATH &#8220;$PATH:\/usr\/local\/bin\/python&#8221; and then click enter.<\/p>\n\n\n\n<p>b. In the bath shell (Linux)- Type export PATH=&#8221;$PATH:\/usr\/local\/bin\/python&#8221; and click Enter.<\/p>\n\n\n\n<p>c. In the sh or ksh shell- Enter Path = &#8220;$PATH:\/usr\/local\/bin\/python&#8221; and click enter.<\/p>\n\n\n\n<p>Remember to note that  &nbsp;\/usr\/local\/bin\/python is considered as the path of the python directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-set-a-path-at-windows\">How to set a path at Windows?<\/h2>\n\n\n\n<p>For adding the Python directory in the path for a particular session in Windows-<\/p>\n\n\n\n<p>At the command prompt &#8211; type path %path%;C:\\Python and then click enter.<\/p>\n\n\n\n<p>Note- C:\\Python is referred to as the path of the Python directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-the-python-environment-variables\">What are the Python Environment Variables<\/h2>\n\n\n\n<p>The important variables that are recognized by Python are the following:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Sr.No<\/td><td>Variable and Description<\/td><\/tr><tr><td>1.<\/td><td>PYTHONPATHL- It works similarly to PATH. This variable will ask the interpreter the location of module files imported into the program.It has the Python source library directory and those directories will have the Python source code. PYTHONPATH can be preset by the Python installer.<\/td><\/tr><tr><td>2.<\/td><td>PYTHONPATHL- It works similarly to PATH. This variable will ask the interpreter the location of module files imported into the program. It has the Python source library directory and those directories will have the Python source code. PYTHONPATH can be preset by the Python installer.<\/td><\/tr><tr><td>3.<\/td><td>PYTHONHOME- It is considered an alternative for the module search path. Thus, it is fixed in the python-startup for changing libraries easily.<\/td><\/tr><tr><td>4\/<\/td><td>PYTHONPATHL- It works similarly to PATH. This variable will ask the interpreter the location of module files imported into the program. It has the Python source library directory and those directories will have the Python source code. PYTHONPATH can be preset by the Python installer.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-run-python\">How to Run Python?<\/h2>\n\n\n\n<p>The 3 different ways to run Python are-<\/p>\n\n\n\n<p><strong>Interactive Python<\/strong><\/p>\n\n\n\n<p>To start Python from Unix, DOS  or any other system will give a command-line interpreter.<\/p>\n\n\n\n<p>Type the Python command line<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$python # Unix\/Linux\nor\npython% # Unix\/Linux\nor\nC:&gt; python # Windows\/DOS<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-add-the-script-from-the-command-line\">How to add the Script from the command line<\/h2>\n\n\n\n<p>Python script will run the command line through the interpreter of the application by entering the command below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$python script.py # Unix\/Linux\n\nor\n\npython% script.py # Unix\/Linux\n\nor\n\nC: &gt;python script.py # Windows\/DOS<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"integrated-development-environment\">Integrated Development Environment<\/h2>\n\n\n\n<p>It is possible to run Python from the Graphical User Interface (GUI) environment as well. Additionally, it has a GUI application on our system that works with Python.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Unix<\/strong>: IDLE is the first IDE (Integrated Development Environment) for Python on Unix systems.<\/li>\n\n\n\n<li><strong>Windows<\/strong>: PythonWin is the initial Windows interface for Python, providing a GUI-based IDE.<\/li>\n\n\n\n<li><strong>Macintosh<\/strong>: Python on Mac comes with the IDLE IDE, available for download from the main website in MacBinary or BinHex&#8217;d files.<\/li>\n\n\n\n<li>If you&#8217;re having trouble setting up Python on your system, ask your system administrator for help. Ensure that Python is set up correctly.<\/li>\n\n\n\n<li>There&#8217;s also an online Python compiler\/interpreter that allows you to edit and run code directly in your browser. Click the run button to execute the provided &#8220;Hello, World!&#8221; code.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>To conclude, this article will allow us to learn the steps to set up a virtual environment in Python. How to Set up Python in Windows and Linux is also included.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"setting-up-virtual-environment-in-python-fa-qs\">Setting Up Virtual Environment in Python-FAQs<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1706782835729\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1.What is virtualenv in Python?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans.  It is referred to as a tool to make a Python-isolated environment.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1706782847158\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. How do I activate venv?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Activating can be done through the command source venv\/bin\/activate<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1706782855428\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. What is an example of a virtual environment?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Email, Chat, and web-based document-sharing applications are some of the examples of virtual environments.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>The Python Virtual Environment System is a tool that functions to confirm that packages on different projects and, will be saved in different places as they won&#8217;t conflict. However, the Python virtual environment will be kept in an isolated place from other projects as it has their dependencies for staying independent. This tutorial will tell &#8230; <a title=\"Setting Up Virtual Environment in Python\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/setting-up-virtual-environment-in-python\/\" aria-label=\"More on Setting Up Virtual Environment in Python\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":6911,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[864],"tags":[57,878],"class_list":["post-6906","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorial","tag-python","tag-virtual-environment","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/6906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=6906"}],"version-history":[{"count":15,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/6906\/revisions"}],"predecessor-version":[{"id":8892,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/6906\/revisions\/8892"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/6911"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=6906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=6906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=6906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}