>> Welcome to Visual Studio 2019.
My name is Tyreke White and I'm
a Program Manager for Python Developer Tools in Visual Studio.
The release of Visual Studio 2019 marks the introduction of
some amazing new features to
enhance the Python developer experience.
These include the ability to bring
your own pre-existing Python code
through Open Folder support and without
the need to create a Visual Studio project.
We've introduced a Python toolbar which
appears whenever you open a Python file,
the toolbar allows you to create Virtual environments,
as well as Conda environments,
and manage packages within those environments.
We now include Miniconda by
default within the Visual Studio Installer.
This decreases installation times
enabling you to get started more quickly with
your code and to create
Conda environments without the need to install Anaconda.
Finally, in this release of Visual Studio,
you can now use live share to share your Python files with
your peers and collaboratively work with them to debug your code.
But showing is better than telling,
so let's dive in and explore these new features.
So now let's demo open folder support in
the Python toolbar Visual Studio 2019.
When you open Visual Studio 2019,
you're given the welcome homepage which allows you to get
started with code by either cloning or checking out from a repo,
opening a project or solution,
opening a local folder or creating a new project.
I'm going to open
my Flask Web app that I've been working on which is here.
So now that my Flask Web app is open,
let's explore it a bit more.
As you can see, I'm given the solution explorer view here on
the right-hand side and this shows me
all of the folders and files that compose my project.
An important thing to note about
this project is the requirements.txt file.
This includes all of the packages and dependencies
that my project will need to function correctly.
As well, these are the packages that IntelliSense will be using to
provide autocompletion as well as
syntax highlighting and all of that good stuff we know and love.
So what we need to do now in order to be able
to run this Flask app is to create
a Virtual environment that has
all the packages contained within this requirements.txt file.
To do that we're going to use
the new Python toolbar, which is here.
I'm going to click the drop-down arrow,
I'm going to scroll down until I find add environment,
click that and it brings up the add environment dialogue.
From here, I can name my project,
I can select the base interpreter for my project,
let's use Python 3.7 and I can install packages from file.
Notice that it's finding that
requirements.txt file I showed you a moment ago.
But if I'm not satisfied with
that file I can choose another by clicking here.
By default, we select "Set as current environment",
because when I create this Virtual environment,
I'm going to be loaded straight into it
without the need to do anything additional.
So let's go ahead and create this flask_demo environment.
Now that we're loaded into our virtual environment,
let's explore it a little bit.
A new feature that we've added is
the manage package icon in this environment,
which is located beside the Python toolbar here.
Clicking this icon brings you
straight into the Python environments tab.
From here you can explore all of
the different virtual environments you have created
within your machine and you can see
all the packages that are included
within the current virtual environment.
These should all look familiar because these are exactly
the packages I installed from the
requirements.txt file a moment ago.
But if I had realized that a packages isn't here that I want,
we can use PyPI and simply type in
the package name and install it.
So what I'm going to do is pip install requests and voila
we now have requests in
our virtual environment and we can see it here.
So now, let's demo this Flask app.
So what I'm going to do is,
I'm going to add a date URL because I'm interested in going to
a URL that tells me today's date as well as the current time.
To do that, I'm going to go to this routes.py file
that I have here and I'm going to create a route for date.
So let's do that now
and as you can see the IntelliSense starts kicking in.
Let's define date and
let date be equal to get_date which is
a function I pre-created at the top of this file.
Finally, for this route,
we need to return render_template.
As you can see, the IntelliSense finds
that and it tells me what I should pass in,
so I need to pass in an HTML,
which I've already created called date,
as well as our date object we just created.
I'm going to save this.
Let's start this application and I'm going to grab this URL
here and I want to go to the date URL that we just created.
Hello there, it's Friday,
March 29th, 2019 and it's 10:54 AM.
Now, let's debug this date URL because I want to show
everyone the cool features we have to offer for debugging.
So to initiate a debugging session in Visual Studio,
I can either press "F5" on
my keyboard or I can press the green arrow here.
So I'm going to press "F5" but you can press the green arrow.
When I initiate that debugging session,
it's going to take me to the first breakpoint that I've set,
which is my import statement at the top.
With debugging in Visual Studio,
you have all of the features we know and love,
such as step into,
step over, step out of.
But, I have another breakpoint set inside of
my date URL that I'm interested in debugging.
So to continue to that next breakpoint again,
I can press the green arrow or "F5" on my keyboard.
Because I set the breakpoint inside of a URL,
in order to actually hit that breakpoint with this Flask Web app,
I'm going to have to go to the browser and type in that date
URL once again, cool.
Now that I've hit the breakpoint,
you can notice that date equals get_date,
where get_date is a function I've defined at the top of this file.
So let's actually step into this
get date function to explore it a bit more,
which I can do by going to
my debugging toolbar and pressing ''Step
into'' right here or "F11."
So now that I've stepped into get_date,
you can see that date is equal to datetime.now.
What's cool is that,
now that I'm inside of this function,
if I step over where I define date,
notice that the locals window pane becomes populated with
the date object as well as the value and the type
which is a datetime object or I can also get
this information by hovering over
date and day 29th
as well as the minute even down to the microsecond, pretty cool.
If I want to step out of this function get_date,
I have two options.
I can either use the step out command,
from the toolbar or
I can scroll down to the line I'm interested in running
to and notice that when I hover beside
that line this green arrow
appears and this is called the "Click-to-Run" button.
I can press this and the app finishes to completion.
Hello there, Visual Studio
2019 allows you to bring your own code no matter the scenario.
So you also get all the same functionality even if
the Python file is embedded within
a larger project like a C++ project.
What's great is that their support for mixed-mode debugging and
IntelliSense to make you even more productive in those scenarios.
As I mentioned earlier,
with Visual Studio 2019 you can
bring any Python code no matter the scenario.
So now what we're going to do,
is I'm going to show you guys a script called
mandelbrot.py which creates and plots a Mandelbrot set.
So as you can see I'm loaded to my familiar page,
have the solution explorer and notice that
mandelbrot.py has one package dependency and that's NumPy.
So again, I'm going to create
a Conda environment for this package,
but keep in mind that you can create
a Conda environment for a different arrangement of packages.
This one just only happens to use NumPy.
So again, I'm going to go to the Python toolbar,
go to Add Environment,
but this time I'm going to select
"Conda Environment" on the left-hand side.
I'm going to name it, let's call it test.
I can add packages from a YML file,
which is a popular Conda package file
or what we've added is the ability
to add one or more Anaconda package names by either
typing them in the search bar here or using this icon.
When you click this "Add Packages" icon,
you'll notice that we've bucketed
the different popular Python workloads
into things such as Data Science Core Libraries,
which is where NumPy lives, Visualization,
Machine Learning and a Web workload
which has Django, Flasks, and Requests.
So I'm going to select
NumPy but also keep in mind that if this Conda
environments or if this Mandelbrot script
needed TensorFlow for example to run,
I could type it in the box here and it would give me a preview of
all the packages that will be installed within
my Conda Environment and then I hit "Create."
So now that I've created my Conda Environment called test,
let's do some more exploration.
So if I go to the Python Environments tab,
recall that I said that this Mandelbrot plot scripts
is going to create and plot a Mandelbrot script.
If I want to plot this in an IPython interactive experience,
one thing I can do is find my Conda Environment test,
go to this icon which opens the Interactive Window and drop down
to this option which says use
IPython interactive mode and hit the checkbox.
So that way I can get the inline figures graphing that a
lot of us no one love, nice.
Now we're ready to explore this script.
In order to start running this script,
there a couple of ways I can run it.
I can select lines that I'm interested in from this code.
So let's select this "Import Statement".
I can right-click and find
the option that reads, Send to Interactive.
Notice that it sends the import statements to
the Interactive Window and there are no errors which is great.
Another way to run this is to select the lines that I'm interested
in again but this time I can use control enter.
As you can see within the Interactive Window,
it sends the two code snippets to
the window and it replies Hello World.
Again no errors.
To be even more productive in these interactive scenarios,
another neat trick you can do is to
decorate different sections of code with #%%,
that way you can send these sections of code
iteratively to the Interactive Window for further inspection.
As you can see, I've decorated different sections with #%% and I'm
going to send these chunks to
the Interactive Window piece by piece.
I can do this again by right-clicking over a section
and selecting "Send to Interactive"
or I can just use "Control Enter".
So I'm going to use "Control Enter".
We send that snippet as well as that snippet,
this snippet, and that snippet.
Notice the warnings that pop up but not a big deal at all.
Now I'm ready to show you guys what
this Mandelbrot plot actually looks like.
So starting from the top I'm going to use
"Control Enter" and everything to the Interactive Window.
There it is, a Mandelbrot plot.
What's great about the inline figure graphing is
that if I see something is off with my figure,
I can compare my figure with
my code and send it back to the Interactive Window.
No need for additional pop-ups or dialogues for plots.
Finally, there is now live share support for Python and
Visual Studio 2019 to
enhance your collaborative coding experience.
In VS 2019 you can initiate a live share session by clicking
the "Live Share" button on the upper right corner of
Visual Studio to generate a link to share with your peers.
Users who join your live share session
will be able to see your Python files,
see IntelliSense from your selected Python Environment and
collaboratively debug through your Python code
off from their own machine.
There you have it, Visual Studio 2019 bring
some powerful sleek tools that will enable you
to bring your own Python code wherever you may be.
Are you ready to get started?
Check out the links here for more info. Happy coding.
[MUSIC]