In this blog we will see the usage of pipenv module of python in windows 10 operating system.

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.


Installation Pipenv Module:

pip install pipenv

Creating Virtual Environment:

Create a new project using Python 3.7, specifically, in the current directory.

pipenv --python 3.7.7

If you see above screenshot, after running pipenv setup command in (C:\Users\Shobh\projects_python\project1), a virtual environment has been created dest=C:\Users\Shobh.virtualenvs\project1-U_jDLmfI , also a pipfile has been created at the same project location: C:\Users\Shobh\projects_python\project1\Pipfile

Content of Pipfile:

This files basically tells from where the packages are installed like source url, what package version & python version.

Virtual Environment Location:

Activate the Virtual Environment:

To activate this project’s virtualenv, run the following: pipenv shell

Packages Installation in Virtual Environment:

pipenv install <package-name>==<version>

Checking the pipfile after this installation.

pipenv lock is used to create a Pipfile.lock , which declares all dependencies (as well as sub-dependencies) of your application, latest versions, hashes for the downloaded files.

If you only want to install a dependencies for a development project only you can mention:

pipenv install -d <package-name>==version

Show graph of installed dependencies:

It give you insight into your dependency graph (pipenv graph).

Existing Project Migration:

Creating a virtual environment for exiting project which already has requirements.txt

When we run the pipenv install in that folder, it automatically create a virtual env., pipfile. And install the packages as per the requirements.txt . This way we can migrate old projects in pipenv.

Lets migrate the existing project:

Checking the pip list inside this virtual environment .

Check the sys.executable inside the virtualenv.

Other useful Commands:

Remove project virtualenv (current directory): pipenv --rm

Install all dependencies for a project (including dev): pipenv install --dev

Check your installed dependencies for security vulnerabilities: pipenv check

Un-installs a provided package and removes it from Pipfile: pipenv uninstall <package-name>

Un-installing everything: pipenv uninstall --all

Generate a lockfile: pipenv lock

For mode details please visit: https://pypi.org/project/pipenv/


Thanks!

Happy Learning! Your feedback would be appreciated!

Leave a comment