{"id":518,"date":"2018-09-18T22:33:38","date_gmt":"2018-09-18T14:33:38","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=518"},"modified":"2018-09-20T00:05:19","modified_gmt":"2018-09-19T16:05:19","slug":"how-to-associate-a-virtualenv-environment-with-a-python-project-in-pycharm","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-to-associate-a-virtualenv-environment-with-a-python-project-in-pycharm\/","title":{"rendered":"How to associate a virtual environment with a Python project in PyCharm"},"content":{"rendered":"<p>When it comes to Python development, <a href=\"https:\/\/www.jetbrains.com\/pycharm\/\" rel=\"noopener\" target=\"_blank\">PyCharm<\/a> is my favourite IDE.<\/p>\n<p>Before working on a new Python project, I like to create a virtual environment and associate it with the corresponding PyCharm project. In case you like this mode of operation, this is how you can associate a virtual environment with a Python project in PyCharm.<\/p>\n<h2>Creating a virtualenv environment for a new Python 3 project<\/h2>\n<p>First, let us create a virtual environment for that new Python 3 project.<\/p>\n<p>Since Python 3.5, the recommended way to create a new virtual environment is through the <a href=\"https:\/\/docs.python.org\/3\/library\/venv.html\">venv module<\/a> within Python 3.<\/p>\n<p>When we have a version later than Python 3.5 installed on an linux environment, we can run the following command to create a virtual environment:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npython3 -m venv proj_1_venv\r\n<\/pre>\n<p>After the command completes, you will find the <code>proj_1_venv<\/code> folder in your current working directory. Inside <code>proj_1_venv<\/code> folder, you will find a <code>bin<\/code> folder that contains the Python binary and scripts to activate and deactivate the virtual environment.<\/p>\n<h2>Associating a virtual environment during PyCharm project creation<\/h2>\n<p>To associate a virtual environment durung PyCharm project creation, you can go through the following screens:<\/p>\n<p>Click on <strong>Create New Project<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-starting-screen.gif\" alt=\"PyCharm CE Version 2018.2.3 starting screen\"\/><\/p>\n<p>Select <strong>Existing Interpreter<\/strong> and click on <strong>...<\/strong> <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-new-project-options-screen-with-existing-interpreter-chosen.gif\" alt=\"PyCharm CE Version 2018.2.3 new project options screen with existing interpreter chosen\" \/><\/p>\n<p>Click <strong>...<\/strong> to select a Python Interpreter<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-add-Python-Interpreter-for-new-project-screen-with-any-Python-Interpreter.gif\" alt=\"PyCharm CE Version 2018.2.3 add Python Interpreter for new project screen with any Python Interpreter\" \/><\/p>\n<p>Include the path to <code>proj_1_venv\/bin\/python<\/code> and click <strong>OK<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-select-Python-Interpreter-for-new-project-screen.gif\" alt=\"PyCharm CE Version 2018.2.3 select Python Interpreter for new project screen\" \/><\/p>\n<p>Click <strong>OK<\/strong> to confirm the virtual environment selection<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-add-Python-Interpreter-for-new-project-screen.gif\" alt=\"PyCharm CE Version 2018.2.3 add Python Interpreter for new project screen\" \/><\/p>\n<p>Click <strong>Create<\/strong> to create a new PyCharm project<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-new-project-options-screen-with-proj_1_venv-chosen-as-the-Python-Interpreter-for-new-project.gif\" alt=\"PyCharm CE Version 2018.2.3 new project options screen with proj_1_venv chosen as the Python Interpreter for new project\" \/><\/p>\n<h2>Associating a virtual environment to an existing PyCharm project<\/h2>\n<p>To associate a virtual environment to an existing PyCharm project, you can go through the following screens:<\/p>\n<p>While your project is selected, click on <strong>PyCharm<\/strong> -> <strong>Preferences...<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-Preferences-Menu-Item-highlighted-for-project_1.jpg\" alt=\"PyCharm CE Version 2018.2.3 Preferences Menu Item highlighted for project_1\" \/><\/p>\n<p>In the Preferences window, select <strong>Project Interpreter<\/strong> for your project<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-Preferences-Screen-with-Project-Interpreter-selected.jpg\" alt=\"PyCharm CE Version 2018.2.3 Preferences Screen with Project Interpreter selected\" \/><\/p>\n<p>Click on the <strong>Project Interpreter<\/strong> dropbox and then click on <strong>Show All...<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-Project-Interpreter-dropbox-collapsed-with-Show-All..-highlighted.jpg\" alt=\"PyCharm CE Version 2018.2.3 Project Interpreter dropbox collapsed with Show All.. highlighted\" \/><\/p>\n<p>In the Project Interpreters Dialog, click on <strong>+<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-Project-Interpreters-Dialog-with-button-highlighted.jpg\" alt=\"PyCharm CE Version 2018.2.3 Project Interpreters Dialog with + button highlighted\" \/><\/p>\n<p>Select <strong>Existing Interpreter<\/strong> and click on <strong>...<\/strong> <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-new-project-options-screen-with-existing-interpreter-chosen.gif\" alt=\"PyCharm CE Version 2018.2.3 new project options screen with existing interpreter chosen\" \/><\/p>\n<p>Click <strong>...<\/strong> to select a Python Interpreter<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-add-Python-Interpreter-for-new-project-screen-with-any-Python-Interpreter.gif\" alt=\"PyCharm CE Version 2018.2.3 add Python Interpreter for new project screen with any Python Interpreter\" \/><\/p>\n<p>Include the path to <code>proj_1_venv\/bin\/python<\/code> and click <strong>OK<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-select-Python-Interpreter-for-new-project-screen.gif\" alt=\"PyCharm CE Version 2018.2.3 select Python Interpreter for new project screen\" \/><\/p>\n<p>Click <strong>OK<\/strong> to confirm the virtual environment selection<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-add-Python-Interpreter-for-new-project-screen.gif\" alt=\"PyCharm CE Version 2018.2.3 add Python Interpreter for new project screen\" \/><\/p>\n<p>Click <strong>OK<\/strong> to select the associated virtual environment for your project<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-Project-Interpreters-Dialog-with-2-Python-environments-and-Ok-button-highlighted.jpg\" alt=\"PyCharm CE Version 2018.2.3 Project Interpreters Dialog with 2 Python environments and Ok button highlighted\" \/><\/p>\n<p>Click <strong>Apply<\/strong> then <strong>OK<\/strong> to confirm the virtual environment for your project<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-Project-Interpreter-with-proj_1_venv-as-the-virtual-environment-with-Apply-and-OK-button-highlighted.jpg\" alt=\"PyCharm CE Version 2018.2.3 Project Interpreter with proj_1_venv as the virtual environment with Apply and OK button highlighted\" \/><\/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-8m\" 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-8m&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-8m&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%2F518&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>When it comes to Python development, <a href=\"https:\/\/www.jetbrains.com\/pycharm\/\" rel=\"noopener\" target=\"_blank\">PyCharm<\/a> is my favourite IDE.<\/p>\n<p>Before working on a new Python project, I like to create a virtual environment and associate it with the corresponding PyCharm project. In case you like this mode of operation, this is how you can associate a virtual environment with a Python project in PyCharm.<\/p>\n","protected":false},"author":1,"featured_media":1286,"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":[375,4],"tags":[546,226,233,255,195,426],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/PyCharm-CE-Version-2018.2.3-starting-screen.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-8m","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/518"}],"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=518"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/518\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1286"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}