1
1

00:00:00,170  -->  00:00:01,540
<v Jose>Hi, and welcome back.</v>
2

2

00:00:01,540  -->  00:00:02,990
In this video, we're going to look at
3

3

00:00:02,990  -->  00:00:06,570
how to create a new project using PyCharm.
4

4

00:00:06,570  -->  00:00:10,140
This is because this section is being re-recorded in 2019,
5

5

00:00:10,140  -->  00:00:12,193
so there may have been a few changes.
6

6

00:00:13,200  -->  00:00:15,930
Let's start by clicking on create new project,
7

7

00:00:15,930  -->  00:00:18,100
and then find a location for your project.
8

8

00:00:18,100  -->  00:00:21,030
I'm going to call it pricing service,
9

9

00:00:21,030  -->  00:00:25,290
in my case, and then select the project interpreter.
10

10

00:00:25,290  -->  00:00:28,880
Make sure it says new environment using Pipenv.
11

11

00:00:28,880  -->  00:00:31,880
Previously in the course we've used Virtualenv,
12

12

00:00:31,880  -->  00:00:33,930
but Pipenv is sort of the new kid on the block.
13

13

00:00:33,930  -->  00:00:36,030
It's gonna make some things a bit easier.
14

14

00:00:36,030  -->  00:00:37,590
It's gonna give you a bit more security
15

15

00:00:37,590  -->  00:00:39,050
when you're installing packages,
16

16

00:00:39,050  -->  00:00:41,730
making sure that the package you're installing is actually
17

17

00:00:41,730  -->  00:00:43,550
the package that you want to instal.
18

18

00:00:43,550  -->  00:00:45,100
And I'll also link a block post
19

19

00:00:45,100  -->  00:00:47,520
in the resources section of this lecture,
20

20

00:00:47,520  -->  00:00:49,370
so that you can go and have a read
21

21

00:00:49,370  -->  00:00:52,800
of the differences between Pipenv and Virtualenv.
22

22

00:00:52,800  -->  00:00:53,760
Once that's done,
23

23

00:00:53,760  -->  00:00:55,810
go ahead and click on create.
24

24

00:00:55,810  -->  00:00:58,760
And what that's gonna do is set up everything you need.
25

25

00:00:58,760  -->  00:01:00,850
So the Pipenv environment.
26

26

00:01:00,850  -->  00:01:03,010
It's also going to set up your PyCharm project,
27

27

00:01:03,010  -->  00:01:04,770
and it's going to give you an issue file
28

28

00:01:04,770  -->  00:01:06,390
called the Pypt file.
29

29

00:01:06,390  -->  00:01:07,223
There we go.
30

30

00:01:07,223  -->  00:01:08,650
And notice that we no longer
31

31

00:01:08,650  -->  00:01:11,550
need a requirements dot txt file.
32

32

00:01:11,550  -->  00:01:12,760
We don't longer need that file
33

33

00:01:12,760  -->  00:01:14,710
because the pypt file is going to include
34

34

00:01:14,710  -->  00:01:18,240
all the packages that we have to instal for this project.
35

35

00:01:18,240  -->  00:01:21,370
The pypt file has some information about the project
36

36

00:01:21,370  -->  00:01:23,520
such as the python version,
37

37

00:01:23,520  -->  00:01:26,143
and we're going to be using this instead.
38

38

00:01:27,140  -->  00:01:29,670
If we do want to instal any packages
39

39

00:01:29,670  -->  00:01:32,650
onto our virtual environment,
40

40

00:01:32,650  -->  00:01:35,280
now it's much easier to do with the new PyCharm
41

41

00:01:35,280  -->  00:01:38,810
by using the project interpreter settings here
42

42

00:01:38,810  -->  00:01:41,270
where you can instal packages.
43

43

00:01:41,270  -->  00:01:42,103
So what we're gonna do is,
44

44

00:01:42,103  -->  00:01:44,460
is we're gonna start off by installing Flask.
45

45

00:01:44,460  -->  00:01:45,910
Just make sure to find Flask
46

46

00:01:45,910  -->  00:01:48,290
when you're installing a new package,
47

47

00:01:48,290  -->  00:01:50,413
and just go ahead and click instal.
48

48

00:01:51,330  -->  00:01:52,710
Now as that instals,
49

49

00:01:52,710  -->  00:01:54,220
it's going to modify your pypt file
50

50

00:01:54,220  -->  00:01:56,590
and it's going to add Flask to it,
51

51

00:01:56,590  -->  00:01:59,863
so that next time you come around to
52

52

00:01:59,863  -->  00:02:01,746
installing packages in this project,
53

53

00:02:01,746  -->  00:02:03,340
you know that you require Flask.
54

54

00:02:03,340  -->  00:02:04,840
You can see that Flask has been installed
55

55

00:02:04,840  -->  00:02:07,890
together with all the other dependent libraries.
56

56

00:02:07,890  -->  00:02:12,440
And here in the pypt file Flask is now equal to a star.
57

57

00:02:12,440  -->  00:02:14,640
What this means is that you depend,
58

58

00:02:14,640  -->  00:02:17,550
or this project depends on the Flask package
59

59

00:02:17,550  -->  00:02:21,240
and you want the latest version of the Flask package.
60

60

00:02:21,240  -->  00:02:24,700
Instead of the star, which just means the latest version,
61

61

00:02:24,700  -->  00:02:28,207
you can put a specific version here, like so.
62

62

00:02:28,207  -->  00:02:32,710
1.0.2, but we no longer wanna do that.
63

63

00:02:32,710  -->  00:02:34,580
We did want to do that when we were using
64

64

00:02:34,580  -->  00:02:36,350
requirements dot txt,
65

65

00:02:36,350  -->  00:02:40,170
but by using pypt file, we say,
66

66

00:02:40,170  -->  00:02:41,910
that we want the latest version.
67

67

00:02:41,910  -->  00:02:45,450
And what happens is that a pipfile.lock file
68

68

00:02:45,450  -->  00:02:47,841
is created as well.
69

69

00:02:47,841  -->  00:02:49,210
Notice that this is news, just been created now.
70

70

00:02:49,210  -->  00:02:53,900
What this does is, it saves the version of Flask
71

71

00:02:53,900  -->  00:02:55,710
that we last installed.
72

72

00:02:55,710  -->  00:02:57,760
So right now we've installed Flask 1.0.2.
73

73

00:02:59,270  -->  00:03:02,430
So you can see that what we've installed here
74

74

00:03:02,430  -->  00:03:03,730
is actually version 1.0.2.
75

75

00:03:04,960  -->  00:03:06,780
So why is this important?
76

76

00:03:06,780  -->  00:03:10,356
Well, it means that if you have a pipfile.lock file
77

77

00:03:10,356  -->  00:03:12,270
in your project,
78

78

00:03:12,270  -->  00:03:14,550
when you go to instal your libraries
79

79

00:03:14,550  -->  00:03:16,410
what Pipenv is going to do is gonna say,
80

80

00:03:16,410  -->  00:03:18,260
okay you depend on Flask,
81

81

00:03:18,260  -->  00:03:20,430
let's go over to the pipfile.lock
82

82

00:03:20,430  -->  00:03:22,670
and instal exactly the same stuff
83

83

00:03:22,670  -->  00:03:25,220
that you have in your pipfile.lock.
84

84

00:03:25,220  -->  00:03:26,470
So why is that good?
85

85

00:03:26,470  -->  00:03:28,900
The main reason is that you can
86

86

00:03:28,900  -->  00:03:31,650
share your pipfile.lock with other developers.
87

87

00:03:31,650  -->  00:03:34,560
If you're working on a large app with other people,
88

88

00:03:34,560  -->  00:03:36,850
you can share the pipfile.lock file with them,
89

89

00:03:36,850  -->  00:03:39,380
so that everybody has exactly the same version
90

90

00:03:39,380  -->  00:03:40,840
at any point in time.
91

91

00:03:40,840  -->  00:03:43,910
If you then want to update to a new Flask version,
92

92

00:03:43,910  -->  00:03:46,170
all you have to do is update.
93

93

00:03:46,170  -->  00:03:48,570
That changes your pifile.lock,
94

94

00:03:48,570  -->  00:03:50,950
and then you can share that with everybody,
95

95

00:03:50,950  -->  00:03:53,220
and then everybody will once again be on the same page.
96

96

00:03:53,220  -->  00:03:54,730
So it gives you a little bit of security
97

97

00:03:54,730  -->  00:03:56,560
that as long as you have the correct,
98

98

00:03:56,560  -->  00:03:59,450
latest pipfile.lock in your project,
99

99

00:03:59,450  -->  00:04:01,940
you are going to be in the same version of any library
100

100

00:04:01,940  -->  00:04:03,590
as everybody else.
101

101

00:04:03,590  -->  00:04:06,323
The other thing is that you have these hashes.
102

102

00:04:07,420  -->  00:04:10,860
These hashes in Pipenv are calculated
103

103

00:04:10,860  -->  00:04:13,010
from the package contents.
104

104

00:04:13,010  -->  00:04:17,260
So what I mean by that is Pipenv is via an algorithm
105

105

00:04:17,260  -->  00:04:19,550
is going to take the package contents,
106

106

00:04:19,550  -->  00:04:23,150
and is going to turn them into this number here.
107

107

00:04:23,150  -->  00:04:25,850
If the code in the package changes at all,
108

108

00:04:25,850  -->  00:04:28,200
so for example, let's say the Flask changes,
109

109

00:04:28,200  -->  00:04:30,100
this number here is going to be different
110

110

00:04:30,100  -->  00:04:32,810
because it's generated from the package contents.
111

111

00:04:32,810  -->  00:04:35,440
And that gives you security.
112

112

00:04:35,440  -->  00:04:37,880
For example, let's say that a malicious user
113

113

00:04:37,880  -->  00:04:39,570
changes the Flask package
114

114

00:04:39,570  -->  00:04:41,970
but does not update the version number.
115

115

00:04:41,970  -->  00:04:44,270
For example, so that they can include some malware
116

116

00:04:44,270  -->  00:04:46,150
in order to compromise your app.
117

117

00:04:46,150  -->  00:04:47,640
This number here would change,
118

118

00:04:47,640  -->  00:04:49,460
and Pipenv would say,
119

119

00:04:49,460  -->  00:04:52,690
the hash has changed, but the version number is the same,
120

120

00:04:52,690  -->  00:04:54,490
this looks a bit suspicious.
121

121

00:04:54,490  -->  00:04:58,330
So that's why Pipenv gives you a bit of security as well,
122

122

00:04:58,330  -->  00:05:01,630
which the requirements dot txt method did not give you.
123

123

00:05:01,630  -->  00:05:05,060
So those are two reasons that I like to use Pipenv,
124

124

00:05:05,060  -->  00:05:06,740
as well as a few other things such as,
125

125

00:05:06,740  -->  00:05:08,860
it tells you what Python version you recommend
126

126

00:05:08,860  -->  00:05:10,730
for this project, and so on.
127

127

00:05:10,730  -->  00:05:13,130
Overall, it's a big improvement, I would say,
128

128

00:05:13,130  -->  00:05:16,530
over the old method, and I recommend you use this
129

129

00:05:16,530  -->  00:05:17,363
moving forward,
130

130

00:05:17,363  -->  00:05:21,610
especially now that PyCharm has support for Pipenv
131

131

00:05:21,610  -->  00:05:22,493
out of the box.
132

132

00:05:23,410  -->  00:05:24,930
All right, that's everything for this video.
133

133

00:05:24,930  -->  00:05:26,210
Thank you for joining me.
134

134

00:05:26,210  -->  00:05:27,660
I'll see you on the next one.
