{"id":2554,"date":"2020-05-03T21:02:27","date_gmt":"2020-05-03T21:02:27","guid":{"rendered":"https:\/\/www.arzhost.com\/?p=1495"},"modified":"2026-04-27T21:54:57","modified_gmt":"2026-04-27T16:54:57","slug":"create-virtual-environment-python-3","status":"publish","type":"post","link":"https:\/\/arzhost.com\/blogs\/create-virtual-environment-python-3\/","title":{"rendered":"The Easy Guide to Creating Virtual Environments Python 3"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Understanding Isolated Python Environments<\/h2>\n\n\n\n<p>Create Virtual Environment Python 3 application uses modules and packages that are not included in the standard library. These applications often require a specific version of the library. The reason is the app often demands to resolve a particular bug or to write an application in an obsolete version.<\/p>\n\n\n\n<p>It is easy to resolve this problem by creating a virtual environment in python 3. It is a self-contained directory tree. In addition to various additional packages, it includes a particular version of python installation.<\/p>\n\n\n\n<p>For more guides like this, visit our <a href=\"https:\/\/arzhost.com\/blogs\/\"><strong>Blog<\/strong><\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Importance and Benefits of Using Isolated Environments<\/strong><\/h2>\n\n\n\n<p>A virtual environment (Virtualenv) is a means to make an isolated python environment. Having its installation directories, virtualenv does not share its libraries with other virtual environments.<\/p>\n\n\n\n<p>Therefore, the virtual environment is recommended and considered the easiest way to organize a custom Python environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Difference Between Virtualenv and Venv<\/strong>: Comparing Two Popular Tools<\/h2>\n\n\n\n<p>Venv comes with <a href=\"https:\/\/arzhost.com\/blogs\/best-python-framework\/\"><strong>Python 3, and Python 2<\/strong><\/a> does not include venv. Virtualenv is a library that delivers more functionality when compared with venv. The following are some features that venv does not contain as compared to virtualenv.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It Venv is slower<\/li>\n\n\n\n<li>Venv is not as extendable,<\/li>\n\n\n\n<li>While Venv cannot make virtual environments for custom installed python versions<\/li>\n\n\n\n<li>Venv cannot be upgraded via pip,<\/li>\n\n\n\n<li>It Venv has not a rich programmatic API<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"536\" src=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/difference-between-virtualenv-and-venv-1-1024x536.jpg\" alt=\"difference between virtualenv and venv\" class=\"wp-image-12136\" srcset=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/difference-between-virtualenv-and-venv-1-1024x536.jpg 1024w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/difference-between-virtualenv-and-venv-1-300x157.jpg 300w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/difference-between-virtualenv-and-venv-1-768x402.jpg 768w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/difference-between-virtualenv-and-venv-1.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">difference between virtualenv and venv<\/figcaption><\/figure>\n<\/div>\n\n\n<p>Yes, it is right that a virtual environment can be created using venv with python 3, even though you are recommended to install and use virtualenv considering the above features.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Installing Virtualenv Using pip3: Installation Guide<\/strong><\/h2>\n\n\n\n<p>Virtual can only be installed on DreamHost servers used for Python 2. While, if it is about Python3, then you must consider and install virtualenv using pip3.<\/p>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-35ffcf87 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><a href=\"https:\/\/arzhost.com\/web-hosting\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/web-hosting\/\">Upgrade Your Hosting Experience\u2014Exclusive 90% Discount Awaits!<\/a><\/h2><p class=\"uagb-cta__desc\">Start Your Online Journey Today\u2014Get <strong>90% Off<\/strong> on Your First Hosting Plan!<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/web-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Custom Versioned Python 3: Managing Different Python Versions<\/strong><\/h2>\n\n\n\n<p>Generally, pip3 is not installed by default on the server. Therefore, a user requires to install a custom versioned Python 3 first. This customed versioned Python 3 also contains pip3. After installation and activation, you can run following the python3 command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;server]$  python3 -m pip install --upgrade pip<\/code><\/pre>\n\n\n\n<p><strong>Once pip3 is upgraded, you can install virtualenv:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[server]$ pip3 install virtualenv<\/code> <code>Collecting virtualenv \nDownloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB) 100% |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 1.8MB 367kB\/s \nInstalling collected packages: virtualenv Successfully installed virtualenv-15.1.0<\/code><\/pre>\n\n\n\n<p><strong>You will want a full path to Python 3 virtualenv. To meet this need, you can use the following command:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;server]$ which virtualenv\n\/home\/username\/opt\/python-3.6.2\/bin\/virtualenv<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Create a Virtualenv Using a Custom Python<\/strong><\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"536\" src=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-create-a-virtualenv-using-a-custom-python-1-1024x536.jpg\" alt=\"how to create a virtualenv using a custom python\" class=\"wp-image-12137\" srcset=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-create-a-virtualenv-using-a-custom-python-1-1024x536.jpg 1024w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-create-a-virtualenv-using-a-custom-python-1-300x157.jpg 300w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-create-a-virtualenv-using-a-custom-python-1-768x402.jpg 768w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-create-a-virtualenv-using-a-custom-python-1.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">how to create a virtualenv using a custom python<\/figcaption><\/figure>\n<\/div>\n\n\n<p>It is liked more to have a custom versioned python over the server\u2019s version. To <a href=\"https:\/\/arzhost.com\/blogs\/creating-a-virtual-environment-python3\/\"><strong>Create a New Virtualenv<\/strong><\/a> with the use of a custom-installed Python version, you can follow these steps:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Installation Instructions: Detailed Steps for Installing Python<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Jot down the full file path installation of custom version python. In the installation article, if you have followed all the instructions, the full path is as;<br><pre class=\"lang:default decode:true \"><code>[server]$ which python3<br>\/home\/username\/opt\/python-3.6.2\/bin\/python<\/code><\/pre><br><\/li>\n\n\n\n<li>You can make a new virtual environment by navigating to the site\u2019s directory:<br><pre class=\"lang:default decode:true \"><code>[server]$ cd ~\/example.com<\/code><\/pre><br><\/li>\n\n\n\n<li>Source your .bash_profile<br><pre class=\"lang:default decode:true \"><code>[server]$ . ~\/.bash_profile<\/code><\/pre><br><\/li>\n\n\n\n<li>Create the virtualenv while you are specifying the version of your desired Python. The following command can be used to create a virtualenv. A flag (-p) is used to determine the full path to the customized Python3 you just installed.<br><pre class=\"lang:default decode:true \"><code>[server]$ virtualenv -p \/home\/example_username\/opt\/python-3.6.2\/bin\/python3 venv<br><br>Run virtualenv with interpreter \/home\/example_username\/opt\/python-3.6.2\/bin\/python3<br>Using base prefix '\/home\/example_username\/opt\/python-3.6.2'<br>New python executable in \/home\/example_username\/example.com\/env\/bin\/python3<br>Also, create executable in \/home\/example_username\/example.com\/env\/bin\/python<br>Install setup tools, pip, wheel...done.<\/code><\/pre><br><\/li>\n\n\n\n<li>You can use the following command for activating the new virtual environment.<br><pre class=\"lang:default decode:true \"><code>[server]$ source venv\/bin\/activate<\/code><\/pre><br><\/li>\n\n\n\n<li>If you verify whether the Python version is correct or not, use the following command.<br><pre class=\"lang:default decode:true\"><code>[server]$ source venv\/bin\/activate[server]$ python -V<br>Python 3.6.2<\/code><\/pre><br><\/li>\n<\/ol>\n\n\n\n<p>Now, you can see the packages have been installed using pip in the folder of the virtual environments project that is isolated from the python installation<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Deactivating your Virtualenv: Safely Exiting the Virtual Environment<\/strong><\/h4>\n\n\n\n<p>Once you have completed your work in the virtual environment and you want to deactivate it, you can run the following command;<\/p>\n\n\n\n<p>[server]$ deactivate<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This command puts you back to the user&#8217;s default settings.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Delete a Virtual Environment: Removing Unneeded Environments<\/strong><\/h2>\n\n\n\n<p>If a user wants to remove a create virtual environment, then he can delete it by deleting the project folder, and the following demand can be used.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;server]$ rm -rf venv<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Install Custom Modules in Python: Adding Modules<\/strong><\/h2>\n\n\n\n<p>When working with Python, it is consider <a href=\"https:\/\/arzhost.com\/blogs\/activate-venv-python-3\/\"><strong>good to create and activate a virtual environment<\/strong><\/a>. The reason is that it provides you with an isolated environment. Any work done in this isolated environment does not affect other environments.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"536\" src=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-install-custom-modules-in-python-1-1024x536.jpg\" alt=\"how to install custom modules in python\" class=\"wp-image-12139\" srcset=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-install-custom-modules-in-python-1-1024x536.jpg 1024w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-install-custom-modules-in-python-1-300x157.jpg 300w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-install-custom-modules-in-python-1-768x402.jpg 768w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2020\/05\/how-to-install-custom-modules-in-python-1.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">how to install custom modules in python<\/figcaption><\/figure>\n<\/div>\n\n\n<p>To install a custom model, you can use pip3;<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a virtual environment after installing a custom versioned Python 3.<\/li>\n\n\n\n<li>You must be assure you are in the same directory of the creat virtual environment.<\/li>\n\n\n\n<li>Now use the following command to activate the Virtualenv.<br><pre class=\"lang:default decode:true \"><code>[server]$ source venv\/bin\/activate<\/code><\/pre><\/li>\n\n\n\n<li>Use pip3 to install a module by the following command:<br><pre class=\"lang:default decode:true \"><code>(venv) [server]$ pip3 install &lt;module&gt;<\/code><\/pre><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-cf5921a7 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><a href=\"https:\/\/arzhost.com\/reseller-hosting\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/reseller-hosting\/\">Launch Your Own Hosting Business\u2014Sign Up Now!<\/a><\/h2><p class=\"uagb-cta__desc\">Start Reselling Hosting with Confidence &#8211; Economy Plan starts at $12.99\/-<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/reseller-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Troubleshoot the Following Problems<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>You Can Face an Error While Creating a Virtualenv: Common Issues<\/strong><\/h4>\n\n\n\n<p>When you are creating a virtualenv with the use of Python3, you can face the following error<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'\n\nOSError: Command \/home\/username\/venv\/bin\/python3 -c \"import sys, pip; sys...d\\\"] + sys.argv&#91;1:]))\" setuptools pip failed with error code 1<\/code><\/pre>\n\n\n\n<p>To avoid this situation, a user has the option to add the following line at the time of installing a custom version in the .bash profile. Hence the user can avoid this error.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export LC_ALL=\"en_US.UTF-8\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Using the Full Path to Your Custom Virtualenv: Ensuring Proper Path Usage<\/strong><\/h4>\n\n\n\n<p>It also happens when you run the command of <a href=\"https:\/\/pypi.org\/project\/virtualenv\/\">virtualenv<\/a>; it is running in a version outside of your custom installation. You must try the following command;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;server]$ which virtualenv\n\n\/home\/user\/opt\/python-3.8.0\/bin\/virtualenv<\/code><\/pre>\n\n\n\n<p>In this way, the user can know the version in the custom python3 directory. Afterward, the user can create a Virtualenv by using the full path as follows;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;server]$ \/home\/user\/opt\/python-3.8.0\/bin\/virtualenv -p \/home\/user\/opt\/python-3.8.0\/bin\/python3 venv<\/code><\/pre>\n\n\n\n<p><strong>Read More:<\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/how-to-fix-403-forbidden-error-wordpress\/\">How To Fix 403 Forbidden Error WordPress<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/how-to-get-the-most-out-of-claude-ai\/\">How To Get The Most Out Of Claude Ai<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/bad-gateway-error-502-the-ultimate-guide-to-quick-fixes\/\">Bad Gateway Error (502): The Ultimate Guide to Quick Fixes<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/a-deep-dive-into-todays-best-linux-distros\/\">A Deep Dive Into Today\u2019s Best Linux Distros<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/domain-investor-terms-powerful-strategy\/\">Domain Investor Terms: Expert Insight on Powerful Strategy<\/a><\/li>\n<\/ul>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding Isolated Python Environments Create Virtual Environment Python 3 application uses modules and packages that are not included in the standard library. These applications often require a specific version of the library. The reason is the app often demands to resolve a particular bug or to write an application in an obsolete version. It is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":7776,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,22,25,29,26,16,15],"tags":[],"class_list":["post-2554","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-buisness","category-hosting","category-knowledge","category-python","category-server","category-tutorial","category-wordpress"],"_links":{"self":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/2554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/comments?post=2554"}],"version-history":[{"count":5,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/2554\/revisions"}],"predecessor-version":[{"id":12140,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/2554\/revisions\/12140"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media\/7776"}],"wp:attachment":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media?parent=2554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/categories?post=2554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/tags?post=2554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}