Start Setting Up Your Development Environment
Time to start setting up your development environment! The IDE you’ll see used in this course is PyCharm. This IDE has some advantages because it will perform some tasks for you automatically. For example, it creates a virtual environment when you start a new project. In this course, you’ll still see how to set one up by hand.
First head over to your terminal and make a new folder called
django-portfolio by using the
mkdir command. Then, move into the folder called
django-portfolio and create a virtual environment with
venv. You’ll use the command
python 3 -m venv .env, where
.env is the name of your virtual environment.
Before you can install any packages in there, you still need to activate the virtual environment. Run the command
source .env/bin/activate. Your prompt will change, and you’ll be inside a virtual environment, so any changes you make will be limited to this environment. Then you can install
00:00 Okay. Let’s get started setting up this development environment. As I mentioned before, I will be using PyCharm for this. PyCharm has some advantages in that it does some of the things that we’re going to do now for you, automatically.
00:14 It creates a virtual environment when you start a new project. So, you wouldn’t have to do some of those things by hand, but to make sure that everyone can work along, we’re just going to set it up by hand. So, for this, I will head over to my terminal.
I’m sitting inside of my
Documents/ folder. Let’s take a look. This is where some knowledge of the command-line interface comes in handy. Inside of this folder, currently we have some Mac-generated files, a
materials/ folder, and I have a folder
portfolio-done/, which contains the finished project that we looked at in section one.
Over here, inside of my new folder, I’m going to say
python3, because I want to use the Python 3 version,
-m, for module—I always think about it as being for make, because we want to make a virtual environment.
So, I’m using this
venv module and I’m going to create a virtual environment that I will name here
.env. You can name this anything, so this could be
my_venv, or whatever you want to call it, but I will call it
. (dot) makes it a hidden folder and, generally, you don’t want to change anything inside of the virtual environment.
you can see that inside of this folder we have a new folder called
.env. This contains our virtual environment. Now, before we can install any packages in here to make sure that they’re safe from the rest of the computer, we will still need to activate the virtual environment.
I will show you how that goes. We need to source it, so I can say
source .env/bin/activate. This is just a folder structure, so I’m going inside of
.env/ folder, inside of the
bin/ folder, and then I’m then sourcing the
After running this command, you can see our prompt changed here. I have
(.env) sitting here at the beginning, and this tells you you’re now inside of a virtual environment, which means you’re safe, good to go.
We can install packages and anything that happens is just going to stay constrained to this virtual environment. So, if we delete this
.env/ folder, everything is going to be gone and your computer is not going to be affected by it.
04:08 Great! That means we’re all set with Django. That essentially completes our setup of the development environment that we need. I’m going to show you now how to open it up in PyCharm. But here, if you’re using a different text editor, you will simply just open it up with that text editor of your choice.
So for this, I head over to PyCharm, open it up, and I’m not going to create a new project, which would do this creation of the virtual environment for me, but instead, I’m heading over to
Documents/ and opening up this
04:51 So, this is how my PyCharm looks when I open it up. And you can see, I have a specific theme. Yours is probably white if you open it up—don’t worry, you can change all this in the settings. What I’m going to do now also, to make it easier for you to see when I’m working on this, I’m going to activate the presentation mode.
Inside of here, I have the
.env/ folder that we created outside of PyCharm. Now, if I had made this project just by creating a new project with PyCharm, this
.env/ folder would already be connected and we would be using it automatically. I’m just going to make sure to connect it. Down here in the terminal, we can see that the virtual environment is already switched on by seeing this
(.env) here in the terminal.
06:26 There’s a way to fix that. I just want to show you this, probably you’re not going to have to use it, but in case, so that you know where to look. Okay, so you go to PyCharm and Preferences…, and you just scroll to your project settings here—that’s going to have the name of whatever the project is that you’re working on.
06:49 Then, you select Project Interpreter, and here, it’s going to tell you, okay, which is the project interpreter that you’re currently working with, and you can see the installed packages coming up here.
07:00 We see that ours is already activated here, which yours is probably also going to be, but if it gets some error or Django is not showing up here, then you’re going to have to connect to the correct one.
07:12 You can do this by clicking on this cogwheel symbol here and then Add…, and then we want to use our existing environment, so click Existing environment, and now we have to find the path to our Python interpreter.
You do this by clicking these three little dots here, and it’s going to open up the file structure. Now you have to navigate your file structure—this is my personal folder—into
Documents/, and then inside of your project,
and here we are in the
.env/ folder. So, you’re going to have to find the Python interpreter and that’s sitting inside of
.env/, then inside of
bin/, and now we want to choose the interpreter, and you can just use this python3 link here.
07:59 It’s going to direct you to the right Python installation, so that’s what you want to choose. So, you have to navigate the file structure all the way to your Python interpreter, then click OK. Now you see it’s showing up here.
08:52 That shows us that we have our virtual environment activated, and that means we’re ready to continue working. And one more thing: if you’re still getting some kind of error popping up, just try to actually close PyCharm and open it again.
09:15 I’m not going to do this now but just so you know, if you have set the virtual environment like this—you have the path defined there, and it’s still throwing an error—just try to restart. It’s the classic turn it off and on again.
Become a Member to join the conversation.