hi there Serdar Yegulalp from InfoWorld at IDG today I'll be showing
Pipenv, a system for creating and managing virtual environments and
packages in your Python projects it gives developers a way to reliably
reproduce the environment they use to develop a project so that everyone uses
the same versions of things and files the same steps to get it set up and
running for this demo the first thing I'm going to do is get pit bends set up
in my Python installation because pip ends manages virtual environments and
packages I can't really install it in a virtual environment I have to install it
in my base underlying Python installation to do this all I have to do
is type pip install pip end now one of the options that I could use this stage
is to add the user flag to install pip and from me alone this way it's not
actually installed in my base Python installation as a hedge against
something going wrong so in fact I'm going to do just that I should also note
that if I do this the installer may complains the place where pip ends puts
its executive Bulls isn't in my path but I took steps earlier to make sure I
don't get that error so be aware that you might get that error if you do this
yourself now let's use pip m to create a new
project what I have here is an empty folder which I will launch a command
line in and from there I just type pip ends - - Python 3.8 to specify which
version of Python to use to initialize a project there once the initialization is
finished we can look at the folder and you'll notice that we don't have a
virtual environment subfolder in it and that's because pip and manages virtual
environments for projects by keeping them in a subdirectory of your user
profile directory if I want to use that virtual environment directly I can just
type in shell and launch a shell session based on that virtual environment also
many IDE s like Visual Studio code which I'll be using for this demo recognize
pit Bend files and we'll configure project to use the virtual environment
specified in it so what do we have in this folder well right now there's only
a single file Pip file this is a plain text file and
that tells us where pit BEM will get packages from for the project and which
packages and what versions to use and also what version of Python is needed
whatever you do don't edit this file directly use pip
and from the command line to make any changes to it for instance for the
project I'm about to demonstrate we'll need the piglet graphics library so we
will install that using Pippin Pippin install piglet version 1.5 v this is the
same syntax we would use for pip itself so you don't have to retool your habits
a great deal to switch from using regular pip to using pip end now once
that's finished you'll notice we have another file in the directory pip file
dot lock this describes all the versions of all the packages installed for the
project including hashes generated from them this way we can ensure both to
ourselves and others that the files we've installed are in fact the right
files just installing something with the same file name isn't it was enough it
has to be bit identical to the version we used before to guarantee that we are
in fact getting the same thing now let's populate this folder with a
couple of Python files for our project and launch Visual Studio code on this
folder and select the virtual environment that was created with it for
pip end you should note that Visual Studio code gives us the option to use
the virtual environment pip M created and so that way we can spawn a shell
session using it in Visual Studio code and run the program with it one other
thing that pip fans will do for us is it separates development requirements from
runtime requirements for instance one of the tools I use most commonly in
development is the black formatting tool now I want to add that to this project
but I don't want to add it as a runtime dependency I'm going to run it as a
development dependency so I would type pip end install - D for development and
the version of black that I want to install and this will install black and
as you can see in the PIP file it's going to be listed separately from
piglet finally pip M gives us something plain old pip doesn't which is
dependency tracking the PIP and graph command will show us what I have
installed and which packages depend on which this way you can see how all of
the packages in a given project travel together with each other they
have to be treated as a single unit finally I should point out that you
don't have to start an entire project from scratch to take
advantage of pip Vance for instance if you run pip and install in an existing
project that has a requirements text file it'll create a virtual environment
import everything from requirements text and generate a pip file from it this way
you can migrate existing projects to pip end without too much headache if you'd
like this video please leave a comment below don't forget to subscribe to The
IDG Tech Talk channel on YouTube and for more Python tips be sure to follow us on
Facebook YouTube and info WorldCom