{"id":1340,"date":"2018-10-28T13:56:11","date_gmt":"2018-10-28T05:56:11","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=1340"},"modified":"2018-10-28T13:56:47","modified_gmt":"2018-10-28T05:56:47","slug":"how-to-install-python3-venv-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-to-install-python3-venv-on-ubuntu-16-04\/","title":{"rendered":"How to install python3-venv on Ubuntu 16.04"},"content":{"rendered":"<p>Since <a href=\"http:\/\/releases.ubuntu.com\/16.04\/\" rel=\"noopener\" target=\"_blank\">Ubuntu 16.04<\/a> is a very popular operating system, it is one operating system that you will likely come across when you are building software with Python 3. For example, if you want to get a <a href=\"https:\/\/www.amazon.com\/NVIDIA-945-82771-0000-000-Jetson-TX2-Development\/dp\/B06XPFH939\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=2ee41478db6213a51b95128b5906b738&language=en_US\" rel=\"noopener\" target=\"_blank\">Nvidia Jetson TX2 developer kit<\/a> today, you will find yourself dabbling with Ubuntu 16.04.<\/p>\n<p>On the other hand, the <a href=\"https:\/\/docs.python.org\/3\/library\/venv.html\" rel=\"noopener\" target=\"_blank\">venv module of Python 3<\/a> is one recommended way to create virtual environments for our <a href=\"https:\/\/www.techcoil.com\/blog\/tag\/python-3\/\" rel=\"noopener\" target=\"_blank\">Python 3 projects<\/a>.<\/p>\n<p>In case you need it, this post describes how to install <code>python3-venv<\/code> on Ubuntu 16.04.<\/p>\n<h2>Add universe repository and update Ubuntu 16.04<\/h2>\n<p>Open up a terminal window. After your terminal window had started, add <a href=\"https:\/\/help.ubuntu.com\/community\/Repositories#Universe\" rel=\"noopener\" target=\"_blank\">Universe repository<\/a> and upgrade your Ubuntu with the following commands:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install software-properties-common -y\r\nsudo apt-add-repository universe\r\nsudo apt-get update\r\n<\/pre>\n<p>After the commands complete, you should be able to install <code>python3-venv<\/code>.<\/p>\n<h2>Installing python3-venv on Ubuntu 16.04<\/h2>\n<p>Next, run the following command to install python3-venv on Ubuntu 16.04:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install python3-venv -y\r\n<\/pre>\n<h2>Creating a virtual environment for your Python 3 application with python3-venv<\/h2>\n<p>Once <code>python3-venv<\/code> had been installed successfully, you should be able to create a virtual environment for your Python 3 application.<\/p>\n<p>In order to test that out, run the following command to create a virtual environment for your Python 3 application inside <code>~\/my_py3_venv<\/code>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npython3 -m venv ~\/my_py3_venv\r\n<\/pre>\n<p>After the command complete, you should be able to find the virtual environment inside the <code>~\/my_py3_venv<\/code> directory.<\/p>\n<h2>Getting into your Python 3 virtual environment with your terminal window<\/h2>\n<p>In order to get into your Python 3 virtual environment with your terminal window, you need to run the <code>activate<\/code> script. Given that, run the following command to get into your Python 3 virtual environment:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsource ~\/my_py3_venv\/bin\/activate\r\n<\/pre>\n<p>After the command complete, you will find that your terminal prompt is appended with <strong>(my_py3_venv)<\/strong>. While inside this virtual environment, you can install any Python dependencies with the <code>pip<\/code> command. For example, if you wish to install <a href=\"http:\/\/flask.pocoo.org\/\" rel=\"noopener\" target=\"_blank\">Flask<\/a>, you can run the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npip install flask\r\n<\/pre>\n<p>When you had installed the necessary dependencies for your Python 3 application, you can then run your application with the <code>python<\/code> binary:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npython run_your_app.py\r\n<\/pre>\n<h2>Getting out of your Python 3 virtual environment<\/h2>\n<p>In order to get out of your Python 3 virtual environment, you need to run the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndeactivate\r\n<\/pre>\n<p>After the command completes, you will find that your terminal prompt is not appended with <strong>(my_py3_venv)<\/strong>. At this point in time, whatever dependencies that you had added while inside the virtual environment will not be available.<\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-lC\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-lC&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-lC&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1340&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>Since <a href=\"http:\/\/releases.ubuntu.com\/16.04\/\" rel=\"noopener\" target=\"_blank\">Ubuntu 16.04<\/a> is a very popular operating system, it is one operating system that you will likely come across when you are building software with Python 3. For example, if you want to get a <a href=\"https:\/\/www.amazon.com\/NVIDIA-945-82771-0000-000-Jetson-TX2-Development\/dp\/B06XPFH939\/ref=as_li_ss_tl?ie=UTF8&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=2ee41478db6213a51b95128b5906b738&#038;language=en_US\" rel=\"noopener\" target=\"_blank\">Nvidia Jetson TX2 developer kit<\/a> today, you will find yourself dabbling with Ubuntu 16.04.<\/p>\n<p>On the other hand, the <a href=\"https:\/\/docs.python.org\/3\/library\/venv.html\" rel=\"noopener\" target=\"_blank\">venv module of Python 3<\/a> is one recommended way to create virtual environments for our <a href=\"https:\/\/www.techcoil.com\/blog\/tag\/python-3\/\" rel=\"noopener\" target=\"_blank\">Python 3 projects<\/a>.<\/p>\n<p>In case you need it, this post describes how to install <code>python3-venv<\/code> on Ubuntu 16.04.<\/p>\n","protected":false},"author":1,"featured_media":1282,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[226,233,586,195,438,224,587],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Ubuntu-Logo.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-lC","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1340"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=1340"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1340\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1282"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=1340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=1340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=1340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}