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