Tutorial on Using venv in PyCharm
3 minute read
Jacques Fleischer
Abstract
This tutorial teaches how to set PyCharm to use a venv.
Contents
Keywords: venv
Windows
Please ensure that you have Git (Git Bash), Python, and PyCharm. If you do not have those, look for the tutorials to install them.
This tutorial was created with the REU program in mind, where the students are provided with a GitHub repository. If you are not in REU, then you can create a new repository on GitHub and clone that instead.
Click the following image to be redirected to a YouTube video tutorial for setting venv in PyCharm. Please keep in mind that this video follows directions that are somewhat different from the written instructions below. REU students should follow the written instructions over the video. Otherwise, in the video, you should skip to timestamp 8:19 unless you do not have Git or a venv, in which case you should watch the entire video.
-
If you have not already cloned your reu repository, you need to follow a separate tutorial which involves setting up your SSH key on GitHub, which can be found here.
-
Open PyCharm. If this is your first time opening PyCharm, then it will say
Welcome to PyCharm
. You should have cloned your repo to a particular location on your computer; clickOpen
and then locate your reu folder. Once you have found it, click on it so it is highlighted in blue and then clickOK
. Alternatively, if you have used PyCharm before, your previous project should open, in which case you should clickFile
andOpen...
to open your repo (if it is not already open). -
Please ensure that you have already configured a venv through Git Bash. If you have not, then read and follow this tutorial.
-
In the top-right of PyCharm, click on the button that reads
Add Configuration...
. ClickAdd new...
on the left underneathNo run configurations added.
and then scroll and clickPython
. Give this a name; you can just typePython venv
. Next toPython interpreter
, choosePython x.x (ENV3)
. Thex.x
will depend on which version of Python you have. Then clickOK
.- The button might not read
Add Configuration...
. If you have configured a run configuration previously, then you can create a new one. Click the button right next to the green play button in the top-right of PyCharm. Then, it should sayEdit Configurations...
which you must click on. Change the Python interpreter to be theENV3
one, as outlined in Step #4.
- The button might not read
-
You also have to click
Python x.x
in the bottom-right of PyCharm, next tomain
. From there, choosePython x.x (ENV3)
. To verify that your virtual environment is working, click onTerminal
in the bottom-left of PyCharm. Click the+
(plus) icon next to Local to start a new terminal. It should say(ENV3)
next to your current working directory. Congratulations!