Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Let's start with taking a look at how to get a pipenv environment installed and setup.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
To start, we need to install pipenv.
0:00
Ironically, we can use pip to install it.
0:03
Python, the -m flag, pip install pipenv.
0:06
Once it's installed, and
inside our working directory,
0:16
we can install packages.
0:19
pipenv manages dependencies
on a per-project basis.
0:21
Therefore, simply by installing packages,
we can start using its benefits.
0:26
For our sample project here, let's
install the popular requests library.
0:31
We do that with pipenv install requests.
0:37
By doing so, we see that pipenv
has done a few things for us.
0:45
First, it created a virtual
environment inside our directory.
0:50
It created a Pipfile for us to use, which
we'll look at in more detail here shortly.
0:53
It downloaded the request library
into our virtual environment and
0:59
it added it to the Pipfile.
1:03
Then it locked the dependencies
in a file called Pipfile.lock.
1:05
We can also define which version
of a package to install.
1:09
Let's install the Python Plotting Library,
1:13
matplotlib, and
specify a specific version.
1:17
pipenv install, again,
you want matplotlib and
1:21
we wanna pin it to version 2.2.2.
1:26
We see that it installs
the package in the Pipfile and,
1:30
again, it locks the dependencies
in Pipfile.lock.
1:34
Now what if we have packages that we
will only need for development and
1:39
not in production?
1:42
We can do that as well.
1:44
Let's install pytest in
a development-only mode.
1:46
Do pipenv install pytest and
add the dev flag.
1:51
We see that pytest has been added and
locked to a dev-packages area.
2:02
Let's write a quick script
that we can run using pipenv.
2:07
Let's create a file in this
directory called main.py.
2:12
We'll touch main.py and it'll open it.
2:16
So inside main.py, we'll import requests,
2:23
And we'll make a request
of the Treehouse site.
2:30
So response will be requests.
2:33
Send a get request to teamtreehouse.com.
2:38
And then we'll simply
print out the status code.
2:46
We ant response.
2:56
Status_code.
2:59
We want the string version of that.
3:01
Pretty basic script.
3:04
Let's save it and
run it from the command line.
3:05
We can run it with pipenv
3:10
run python main.py.
3:14
And there's our result,
a 200 code for okay.
3:18
Running our script with pipenv run,
3:23
make sure that our install
packages are available.
3:25
In the next video, let's take a closer
look at the two files pipenv created and
3:29
populated for us, Pipfile and Pipfile.log.
3:34
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up