1
00:00:00,780 --> 00:00:04,110
So we have a running website which looks quite good.

2
00:00:04,110 --> 00:00:07,510
The problem is that this is in our local host.

3
00:00:07,800 --> 00:00:10,780
So the only person seeing this is you.

4
00:00:11,010 --> 00:00:14,970
Or someone who has access to your computer.

5
00:00:15,000 --> 00:00:21,930
So what we want to do instead is to deploy this website on a web server or on cloud as we will do

6
00:00:21,930 --> 00:00:23,260
in this course.

7
00:00:23,540 --> 00:00:25,600
I will be using the Heroku Cloud.

8
00:00:25,800 --> 00:00:31,650
Heroko is a service that allows you to deploy Python applications in their Cloud.

9
00:00:31,650 --> 00:00:36,750
The good news is that you can deploy an application for free and you can have your public domain for

10
00:00:36,750 --> 00:00:43,960
free as well though you'll need a subdomain of Heroku so o something like let's say Ardit.heroku.com.

11
00:00:44,010 --> 00:00:51,720
However if your site will have a lot of traffic later on you want to actually upgrade your plan and buy

12
00:00:51,720 --> 00:00:56,030
more bandwidth. Deploying on Heroko is relatively easy.

13
00:00:56,040 --> 00:01:00,290
You don't have to think to do any administrative work.

14
00:01:00,300 --> 00:01:07,950
So Heroko saves a lot of time and effort so that you can focus on programming instead of the server parts.

15
00:01:07,950 --> 00:01:17,010
Before deploying to Heroku though we need to do something. There is  something that we should have done

16
00:01:17,010 --> 00:01:19,700
since in the beginning of the section.

17
00:01:19,710 --> 00:01:26,550
So even before writing any file here. What you should do is that you should create a virtual environment

18
00:01:27,120 --> 00:01:32,690
which is isolated from your other files from your main Python installation.

19
00:01:32,820 --> 00:01:39,720
So to run our application we use Python which is coming from our main installation.

20
00:01:40,710 --> 00:01:49,980
So this one here, the ones I have here. This is not a good practice. A good practice is to actually have a clean

21
00:01:49,980 --> 00:01:53,430
installation of Python which is used only for application.

22
00:01:53,610 --> 00:01:58,920
So in that installation you don't want to have libraries installed, the libraries that you don't need

23
00:01:58,920 --> 00:02:01,470
for building fast applications.

24
00:02:01,470 --> 00:02:04,760
Therefore we need to create a virtual environment.

25
00:02:05,100 --> 00:02:09,030
And here I will show you how you can do that. To create a virtual environment

26
00:02:09,030 --> 00:02:15,840
you need to use a Virtualenv Python library and to use the virtual Python library you need to install Virtualenv

27
00:02:15,840 --> 00:02:19,440
So pip install Virtualenv.

28
00:02:19,790 --> 00:02:30,280
So we are using the main Python isolation here to install Virtualenv. Great, that was successful installed.

29
00:02:30,610 --> 00:02:34,270
And now we will create a virtual environment.

30
00:02:34,280 --> 00:02:41,070
The virtual environments should be created at the same level with a main folder that holds the

31
00:02:41,070 --> 00:02:43,600
application files.

32
00:02:43,650 --> 00:02:52,890
So if we go to our directory just here, here is where the files are and what I'll do is create a main

33
00:02:52,890 --> 00:02:54,690
folder in here.

34
00:02:54,940 --> 00:02:58,290
And call it my site.

35
00:02:58,290 --> 00:03:03,790
And I'd close Atom for a while and this would go inside this.

36
00:03:03,900 --> 00:03:10,650
So just here and now you can open Atom in this directory because here is where we will create

37
00:03:10,650 --> 00:03:13,140
the virtual environment.

38
00:03:14,370 --> 00:03:22,860
So let's open the command line now and we are ready to create a virtual environment and to do that you

39
00:03:22,860 --> 00:03:31,200
should use a Virtualenv library by saying Python, the M argument, then you have Venv which is the

40
00:03:31,200 --> 00:03:33,560
name of the library, of the module.

41
00:03:33,750 --> 00:03:41,190
And M here is an argument who allows Python to locate modules for execution as scripts.

42
00:03:41,430 --> 00:03:47,830
Then you need to specify a name for the folder where the virtual environment files will be stored in.

43
00:03:47,840 --> 00:03:48,140

44
00:03:48,150 --> 00:03:50,100
So that should work.

45
00:03:50,140 --> 00:03:58,140
Let's see. The virtual folder was created and the environment was created successfully.

46
00:03:58,250 --> 00:04:04,890
What we have here is an isolated installation of Python and inside Scripts you will see that you have

47
00:04:05,070 --> 00:04:07,910
Python there.

48
00:04:07,940 --> 00:04:09,100
Here it is.

49
00:04:09,480 --> 00:04:09,900
Ok.

50
00:04:09,900 --> 00:04:11,430
Don't worry about that.

51
00:04:11,790 --> 00:04:13,340
And here is pip as well.

52
00:04:13,400 --> 00:04:15,420
So pip.exe.

53
00:04:15,900 --> 00:04:18,710
And that means you can use that Python if you like.

54
00:04:19,010 --> 00:04:27,390
Let me try out. So we are now at the My site directory.

55
00:04:27,480 --> 00:04:39,090
That means we need to refer to virtual, Scripts and Python and that will trigger or fresh Python in the

56
00:04:39,090 --> 00:04:40,140
console.

57
00:04:40,140 --> 00:04:45,550
However we are not interested to actually run Python from the shell.

58
00:04:46,140 --> 00:04:53,670
So I'll just exit this and what we're interested instead is to actually run the Flask application using

59
00:04:53,680 --> 00:04:55,790
the fresh installation of Python.

60
00:04:56,040 --> 00:05:01,830
But before we do that we need to actually install Flask in our virtual Python if you like and to do

61
00:05:01,830 --> 00:05:06,370
that you need to use the pip library of your isolated Python.

62
00:05:07,250 --> 00:05:15,110
So you need to point to the visual folder, to the script folder then and then to pip install flask.

63
00:05:19,920 --> 00:05:26,100
And so flask is installing and it also installed its dependencies.

64
00:05:26,330 --> 00:05:27,770
And we should be good to go now.

65
00:05:27,960 --> 00:05:36,870
So let's run our web app using our new installation of Python. To do that you need to point to the new

66
00:05:36,930 --> 00:05:47,230
Python and then to demo because we are in my site now, as you see here. So Demo backslash script1.py.

67
00:05:47,230 --> 00:05:47,750

68
00:05:48,000 --> 00:05:54,750
That should work. Great and if you go to the website now

69
00:05:57,750 --> 00:06:00,320
you'll see that it's working fine.

70
00:06:00,640 --> 00:06:01,490
That's it.

71
00:06:01,500 --> 00:06:07,440
Now you are more than ready to deploy your Flask application on the Cloud and we will do just that in

72
00:06:07,440 --> 00:06:08,480
the next lecture.

73
00:06:08,640 --> 00:06:14,550
And I would like to mention again that please keep in mind that you should always create a virtual environment

74
00:06:14,760 --> 00:06:17,360
before you create your Flask application.

75
00:06:17,700 --> 00:06:22,080
So before writing any code you should use a fresh installation of Python.

