Python for the .NET developer Transcripts
Chapter: The Python Language
Lecture: Creating the Python project
0:00 All right, time for some Python.
0:02 You've seen the C# code over here
0:04 and we haven't looked at most of it
0:06 but you can imagine the web part
0:08 the website that we're going to build in Python
0:10 the testing parts, the testing we're going to build.
0:12 We're not starting from any code at all
0:15 when it comes to Python.
0:16 We're going to write every single bit of it
0:18 during this course, which I think
0:20 really helps you internalize it
0:22 and see how it's put together in the whole flow.
0:25 So what we're going to do is we're going to create
0:26 a new project, we already started with our C# code
0:29 with our solution and our projects
0:31 and our project structure and all that over here
0:33 so we're going to do that right now for Python.
0:36 With Python, I could just create a file here
0:38 and start working on a directory
0:39 and then put a file in it potentially.
0:41 There's not really a project structure I have to create.
0:44 But I want to use something called PyCharm.
0:47 PyCharm, which I already introduced earlier
0:49 is a really excellent editor.
0:51 If you don't want to use PyCharm
0:52 then also VS Code with a Python plugin is super good
0:55 similar setup here anyway.
0:58 For Python, what we're going to do is you want to create
1:00 something called a virtual environment.
1:02 When you install Python, it gets installed
1:04 into your system and it has some packages
1:06 and libraries set up and some configuration.
1:09 But if you want true isolation
1:11 so this project has its own set of files
1:14 and is completely isolated from all the other things
1:17 that might have happened on your operating system
1:19 what you do is you create this thing
1:21 called a virtual environment.
1:22 So we're going to create a virtual environment
1:23 and then load this into PyCharm.
1:25 So let's just jump into the terminal over here on
1:28 it's a little extension I have called GoToShell
1:31 and you see, there's nothing here yet.
1:34 What we're going to do is we're going to create
1:36 what's called this virtual environment
1:38 and the way we're going to do that is we're going to
1:39 type python3 here.
1:42 On Windows, you can, depending on how you install it
1:45 you may or may not be able to type python3
1:47 so just do python but here I'm going to do
1:49 python3 -m to run a module.
1:51 The module is called venv for virtual environment
1:54 and the folder we're going to create is also venv.
1:58 Now we have this folder here and this is basically
2:01 a copy of Python and the entire Python run time.
2:04 Sort of symlinks back, but basically it's a copy of Python
2:07 think of it that way, at least conceptually.
2:09 Now in order to use it, we have to activate it.
2:12 So we can say source venv/bin/activate.
2:17 And notice our prompt changes.
2:18 On Windows, don't have this course source concept
2:21 you say venv\scripts\activate.bat
2:26 I don't know why those have to be different, but they are.
2:29 Okay so now we have this as our active Python here.
2:35 We can load up this project into PyCharm
2:38 and when we install stuff like libraries we want to use
2:41 think NuGet packages and other stuff like that
2:43 what we're going to configure is this little local version
2:47 this local version of Python, so whatever we do
2:50 it's absolutely exactly as we want it
2:52 and it's not affected by the other stuff.
2:54 Not technically necessary but a very good practice
2:58 so we're doing it right at the start of this project.