Skip to main content

Pipenv - Welcome NPM

Sham Sui Po, Hong Kong

Pipenv automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages. It also generates the ever-important Pipfile.lock, which is used to produce deterministic builds.

Pipenv is primarily meant to provide users and developers of applications with an easy method to setup a working environment. For the distinction between libraries and applications and the usage of setup.py vs Pipfile to define dependencies

Working with Pipenv

It is recommended that users on most platforms should install pipenv from pypi.org using :

pip install pipenv

Installing Packages for your Project

Pipenv manages dependencies on a per-project basis. To install packages, change into your project’s directory (or just an empty directory for this tutorial) and run:

mkdir myproject && cd myproject
pipenv install requests

✔ Successfully created virtual environment!
Virtualenv location: ~/.local/share/virtualenvs/myproject-VE5iXAN5
Creating a Pipfile for this project...
Installing requests...
Pipfile.lock not found, creating...
Locking [packages] dependencies...
Locking [dev-packages] dependencies...
Updated Pipfile.lock (a416d48a2c30d4acf425cb96d7ac6672753db8e8f6c962a328848db5b9a290a1)!
Installing dependencies from Pipfile.lock (a290a1)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

Using installed packages

./main.py

Now that Requests is installed you can create a simple main.py file to use it:

import requests

response = requests.get('https://httpbin.org/ip')

print('Your IP is {0}'.format(response.json()['origin']))

Then you can run this script using pipenv run:

pipenv run python main.py